Oracle分组函数之CUBE
功能介绍:
首先是进行无字段的聚合,然后依次对每个字段进行聚合
创建表:
View Code
插入测试数据:
View Code
ROLLUP:
Select t.classid,t.studentname,Sum(t.score) From Score t Group By Rollup(t.classid,t.studentname);
查询结果:
Cube:
Select t.classid,t.studentname,Sum(t.score) From Score t Group By Cube(t.classid,t.studentname);
查询结果:
相对于collup,多个如图的8行记录:
Rollup(t.classid,t.studentname):统计的分组列包括()、(classid)和(classid,studentname)
Cube(t.classid,t.studentname):统计的分组列包括()、(classid)、(studentname)和(classid,studentname)