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!

Add summary row

Johnny BJan 26 2016 — edited Jan 26 2016

Hi all,

I have a query with multiple union all from tables and views, each select is one data group, example:

<cfquery name="preQry" dbtype="query">

select 'groupA' as Grouping, Item as Descr, sum(fieldCalA) as fieldTotal

from tableA

group by Grouping, Desc

union all

select 'groupB' as Grouping, item as Descr, sum(fieldCalA) as fieldTotal

from viewB

group by Grouping, Desc

.....

</cfquery>

The data looks like:

GROUPING, DESCR, FIELDTOTAL

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

groupA, ItemA, 10

groupA, ItemB, 25

groupB, ItemC, 30

groupB, ItemD, 20

groupB, ItemE, 50

groupC, itemF, 5

How can I add a summary row for each group?

The final data display as:

DESCR, FIELDTOTAL

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

groupA, 35

   ItemA,10

   ItemB, 25

groupB, 100

  ItemC, 30

  ItemD, 20

  ItemE, 50

groupC, 5

  ItemF, 5

Any ideas or help will be appreciate.

Thanks!

This post has been answered by Scott Swank on Jan 26 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 23 2016
Added on Jan 26 2016
3 comments
512 views