ORCAL grop by的增强 rollup

本案所操作的表为系统自带的emp表

一、试用deptno和job分组

SQL:select deptno,job, sum(sal) sumsal from emp group by deptno,job

获取结果

 二、使用 deptno进行分组

SQL:select deptno, sum(sal) sumsal from emp group by deptno

获取结果

 

三、不进行分组

SQL:select sum(sal) sumsal from emp

 

四、使用rollup

SQL:select  deptno,job, sum(sal) from emp group by rollup(deptno,job)

能做到对每个部门工资都有一个小计,并且能够对公司工资有一个总计  作用与上面三条SQL相加效果相同

猜你喜欢

转载自blog.csdn.net/L_Person/article/details/84589965