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!

How to get subtotals

Agowda-OracleSep 21 2018 — edited Sep 21 2018

Hi All

Here is the sample data from the view

Select

     QTR,

    vendor  ,

    vendor\_id,

    amount,approved\_date

FROM  RENEWALS\_V   where rownum\<10

pastedImage_0.png

I use the below query to get subtotals for each quarter get the output

SELECT

    case row\_number() over(PARTITION BY rv.QTR

                               ORDER BY rv.VENDOR

                               )

     when 1 then rv.qtr end Quarter,

     QTR,

    vendor  ,

     (sum(rv.amount)) AS total

FROM   RENEWALS\_V rv where

 rv.QTR in  (select q.QTR from quarters q where ( (trunc(q.qtr\_Start\_dt)  between trunc(sysdate-455) and  trunc(sysdate)))

OR sysdate between q.qtr\_Start\_dt and q.qtr\_end\_dt )

 GROUP BY GROUPING SETS (( QTR,Vendor),(QTR) )

order by QTR Desc

pastedImage_1.png

I would like to get the subtotals labeled as subtotals.What changes should be made to the above query?

pastedImage_0.png

Thanks

Archana

This post has been answered by mNem on Sep 21 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 19 2018
Added on Sep 21 2018
4 comments
6,488 views