Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 31 2009
Added on Apr 29 2009
9 comments
14,484 views