Departmentwise Subtotal and Grand Total...
NTRApr 29 2009 — edited May 3 2009 Dear All,
Can anyone help me please.........
how to get the departmentwise Subtotal and Grand Total of the table emp.....
I have written the query using with clause as foillows,But i am getting an error Invalid Number.
with t as
(select deptno ,empno , sal from emp
union all select deptno , empno , sal from emp
union all select deptno , empno , sal from emp
union all select deptno , empno , sal from emp
union all select deptno , empno , sal from emp)
select decode(grouping(empno), 0, empno, 'GRAND TOTAL') empno,
decode(grouping(deptno), 0, deptno, decode(grouping(empno), 0, 'SUBTOTAL')) deptno,
sum(sal) num_total
from t
group by rollup(empno, deptno)
/
Thanks & Regards,
Nagaraj