27,580
社区成员
发帖
与我相关
我的任务
分享
with tb(id,number,grade,school)as(
select 1,100,'一年级','一小' union all
select 2,120,'二年级','一小' union all
select 3,130,'一年级','二小' union all
select 4,80,'二年级','二小')
select school,SUM(number) as '学生人数',SUM(case when grade='二年级' then number else 0 end) as '二年级人数' from tb group by school order by school desc
with tb(id,number,grade,school)as(
select 1,100,'一年级','一小' union all
select 2,120,'二年级','一小' union all
select 3,130,'一年级','二小' union all
select 4,80,'二年级','二小')
select school,SUM(number) 学生人数,
max(case when grade='二年级' then number else 0 end) as 二年级人数
from tb group by school order by 1 desc