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!

Using SQL Rollup

szslNov 11 2019 — edited Nov 11 2019

Hi,

Would it be possible to use SQL to display the data below in the following format? The only clause I could partially figure out using is group by rollup. What other SQL clauses do I have to use to display the output in the desired format?

create table emp (id number, name varchar2(10), dept number, salary number, bonus number);
insert into emp values (3,'MILLY',2,5000,50);
insert into emp values (5,'JANE',1,10000,10);
insert into emp values (1,'JILL',1,1000,1);
insert into emp values (2,'LILY',2,6000,60);
insert into emp values (4,'GEORGE',2,4000,40);
commit;

       DEPT            ID     NAME  SUM(SALARY)  SUM(BONUS)

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

          1             1     JILL         1000          1

                        5     JANE        10000         10

Subtotal                                  11000         11

          2             2     LILY         6000         60

                        3    MILLY         5000         50

                        4   GEORGE         4000         40

Subtotal                                  15000        150

TOTAL                                     26000        161

Thanks.

This post has been answered by Stew Ashton on Nov 11 2019
Jump to Answer
Comments
Post Details
Added on Nov 11 2019
6 comments
621 views