oralce GROUPING

/ * From the above results, we can easily find the corresponding statistics for each row will appear null,

How is it to distinguish in the end, grouping function to determine whether the total columns according to the summary field to do! * /

 

select decode(grouping(id),1,'all id',id) id,

decode(grouping(area),1,'all area',to_char(area)) area,

decode(grouping(stu_type),1,'all_stu_type',stu_type) stu_type,

sum(score) score

from students

group by cube(id,area,stu_type)

order by id,area,stu_type;

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11118930.html