当前位置: 移动技术网 > IT编程>数据库>Oracle > Group By Rollup

Group By Rollup

2019年03月15日  | 移动技术网IT编程  | 我要评论

rollup与group by组合使用,可对分组结果进行进一步的汇总。

 

创建数据表

select * from emp_test

 

(1) rollup单个字段

如按照country字段进行分组,并在最后追加一条汇总所有country的值

select gender,country,count(1)
from emp_test
group by rollup (country)

 

(2) rollup多个字段

按照gender,country字段进行分组,并针对每一个country追加一条汇总值,并在最后追加一条所有country汇总

select gender,country,count(1)
from emp_test
group by rollup (country,gender)


rollup后面的字段顺序不同,结果也不同,取决于第一个字段,如:
select gender,country,count(1)
from emp_test
group by rollup (gender,country)

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网