Doris ROLLUP使用

AGGREGATE KEY模型

CREATE TABLE IF NOT EXISTS test.aggregate_test1
(
    `user_id` LARGEINT NOT NULL COMMENT "用户id",
    `city` VARCHAR(20)  COMMENT "所在城市",
    `date` DATE NOT NULL COMMENT "数据插入时间",
    `age` SMALLINT COMMENT "用户年龄",
`last_date` DATETIME REPLACE_IF_NOT_NULL DEFAULT "2022-01-01 00:00:00" COMMENT "用户最后一次访问时间",
`last_date_not_null` DATETIME REPLACE_IF_NOT_NULL DEFAULT "2022-01-01 00:00:00" COMMENT "用户最后一次访问时间",
 
    `cost` BIGINT REPLACE_IF_NOT_NULL DEFAULT "0" COMMENT "总消费",
    `max_dwell_time` INT REPLACE_IF_NOT_NULL DEFAULT "0" COMMENT "最大停留时间",
    `min_dwell_time` INT REPLACE_IF_NOT_NULL DEFAULT "0" COMMENT "最小停留时间"
)
AGGREGATE KEY(`user_id`, `city`, `date`, `age`)
DISTRIBUTED BY HASH(`user_id`) BUCKETS 8;
 

 insert into test.aggregate_test1 values\
(10000,'北京','2022-04-01',20,'2022-10-01 06:00:00','2022-10-01 06:00:00',20,10,10),\
(10000,'北京','2022-04-01',20,'2022-10-01 07:00:00','2022-10-01 07:00:00',15,2,2),\
(10001,'北京','2022-04-01',30,'2022-10-01 17:05:45','2022-10-01 07:00:00',2,22,22),\
(10002,'上海','2022-04-02',20,'2022-10-02 12:59:12',null,200,5,5),\
(10003,'广州','2022-04-02',32,'2022-10-02 11:20:00','2022-10-02 11:20:00',30,11,11),\
(10004,'深圳','2022-04-01',35,'2022-10-01 10:00:15','2022-10-01 10:00:15',100,3,3),\
(10004,'深圳','2022-04-03',35,'2022-10-03 10:20:22','2022-10-03 10:20:22',11,6,6);
 
ALTER TABLE aggregate_test1 ADD  ROLLUP  test_rollup1 (user_id,cost);

explain SELECT user_id, sum(cost) FROM u_test1 GROUP BY user_id;

你可能感兴趣的:(数据库,java,sql)