数据
--复杂统计函数
CREATE TABLE t3 (color_type varchar(20), in_date varchar(30),color_count int);
INSERT INTO t3 (color_type,in_date,color_count) VALUES('black','2010-09-11',18);
INSERT INTO t3 (color_type,in_date,color_count) VALUES('black','2010-10-05',18);
INSERT INTO t3 (color_type,in_date,color_count) VALUES('black','2010-10-13',31);
INSERT INTO t3 (color_type,in_date,color_count) VALUES('blue','2010-09-21',23);
INSERT INTO t3 (color_type,in_date,color_count) VALUES('blue','2010-09-30',15);
INSERT INTO t3 (color_type,in_date,color_count) VALUES('blue','2010-10-11',62);
INSERT INTO t3 (color_type,in_date,color_count) VALUES('red','2010-09-12',41);
INSERT INTO t3 (color_type,in_date,color_count) VALUES('red','2010-10-01',12);
INSERT INTO t3 (color_type,in_date,color_count) VALUES('red','2010-10-05',11);
函数简介
CUBE(a, b, c):和grouping sets((a,b,c),(a,b),(a,c),(a),(b,c),(b),(c),())是等效的
如下所示:
其中:
- black共计67,
- blue共计100
- red共计64
- 所有共计231
添加汇总额外信息
如下所示,添加了总计、小计等信息: