oralce GROUPING SETS

select id,area,stu_type,sum(score) score

from students

group by grouping sets((id,area,stu_type),(id,area),id)

order by id,area,stu_type;

 

/*--------理解grouping sets

select a, b, c, sum( d ) from t

group by grouping sets ( a, b, c )

 

等效于

 

select * from (

select a, null, null, sum( d ) from t group by a

union all

select null, b, null, sum( d ) from t group by b

union all

select null, null, c, sum( d ) from t group by c

)

*/

猜你喜欢

转载自www.cnblogs.com/fanweisheng/p/11118867.html