结果
departmentid classid summath uv
NULL NULL 1654 20
department1 NULL 718 9
department1 class1 410 5
department1 class2 308 4
department2 NULL 936 11
department2 class1 520 6
department2 class2 416 5
等价于union all:
-- 下钻
select departmentid,classid,sum(math) as sumMath,count(distinct studentid) as uv from student_scores
group by departmentid,classid
union all
select departmentid,null as classid,sum(math) as sumMath,count(distinct studentid) as uv from student_scores
group by departmentid,null
-- 上卷
union all
select null as departmentid,null as classid,sum(math) as sumMath,count(distinct studentid) as uv from student_scores
group by null,null;
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx