-- flinksql_019: 全局分组 + 过滤统计 -- 生成 3000 行/秒的交易事件流,使用反引号包裹保留字 -- 1. 交易事件流 datagen 源表(无事件时间/Watermark) CREATE TABLE trade_source ( trade_id BIGINT, `type` INT, `status` INT, amount DOUBLE ) WITH ( 'connector' = 'datagen', 'rows-per-second' = '3000', 'fields.trade_id.kind' = 'random', 'fields.trade_id.min' = '1', 'fields.trade_id.max' = '1000000000', 'fields.type.kind' = 'random', 'fields.type.min' = '1', 'fields.type.max' = '5', 'fields.status.kind' = 'random', 'fields.status.min' = '0', 'fields.status.max' = '2', 'fields.amount.kind' = 'random', 'fields.amount.min' = '0', 'fields.amount.max' = '5000' ); -- 2. Console 输出表 CREATE TABLE console_output ( `type` INT, trade_cnt BIGINT, total_amount DOUBLE ) WITH ( 'connector' = 'print' ); -- 3. 过滤 status=1 + 按 type 分组统计 INSERT INTO console_output SELECT `type`, COUNT(*) AS trade_cnt, SUM(amount) AS total_amount FROM trade_source WHERE `status` = 1 GROUP BY `type`;