(1)
select name,subject,result from resultInfo
(2)
select name,sum(result) from resultInfo group by name
(3)
select name ,sum(result) as 总分 from resultInfo group by name with cube select case when grouping(name)=1 then ‘总计‘ else name end as 姓名 ,sum(result) as 总分 from resultInfo group by name with cube
grouping函数:如果列中的值来来自查询数据,则grouping返回0,如果列中的值是cube产生的空值,则返回1
(4)
select name ,sum(result) as 总分 from resultInfo group by name with rollup select case when grouping(name)=1 then ‘总计‘ else name end as 姓名 ,sum(result) as 总分 from resultInfo group by name with rollup
(5)
select name,subject,sum(result) as 总分 from resultInfo group by name,subject with cube
按第一、二个字段的和计和最后的总计
(6)select name,subject,sum(result) as 总分 from resultInfo group by name,subject with rollup
按第一个字段的总计和最后的合计