Forum Stats

  • 3,874,702 Users
  • 2,266,767 Discussions
  • 7,911,956 Comments

Discussions

Pivot with option to generate column to aggregate all data

Nimish Garg
Nimish Garg Member Posts: 3,185 Gold Trophy
edited Jun 22, 2016 4:13AM in Database Ideas - Ideas

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....

Nimish GargRaj KushawahaSven W.markmevansFatMartinRManikAnnEdmunduser8910179
8 votes

Active · Last Updated

Comments