Skip to Main Content

Database Software

Pivot with option to generate column to aggregate all data

Nimish GargJun 22 2016 — edited Jun 22 2016

Like having a wild-card option to generate new column which aggregate all values as

select * from

(

    select

        sal, deptno, job

    from

        emp

)

pivot

(

    sum(sal) for deptno in (10,20,30,'*' as TOTAL)

);

JOB               10         20         30     TOTAL

--------- ---------- ---------- ---------- ---------

CLERK           1300       1900        950      4150

SALESMAN                              5600      5600

PRESIDENT       5000                            5000

MANAGER         2450       2975       2850      8275  

ANALYST                    6000                 6000

Or Something like this....

Comments
Post Details
Added on Jun 22 2016
6 comments
383 views