Thursday, 7 July 2011

sum of totals query Row and Column

    SELECT     *
      FROM     (SELECT job,
                 sum(decode(deptno,10,sal))  DEPT10,
                    sum(decode(deptno,20,sal)) DEPT20,
                    sum(decode(deptno,30,sal)) DEPT30,
                    sum(decode(deptno,40,sal)) DEPT40,
                    sum(sal)                   TOTAL                    
               FROM emp
              GROUP BY job)
   ORDER BY 1;

No comments:

Post a Comment