Skip to Main Content

total and average - simultaneously in the summary

tdobeSep 4 2022

Hi everyone,
Such a simple way to do the sum of the values of the selected columns, or the average and others. But how can you make the summary be composed of two rows, in the first SUM, and in the second row, for example, the average?

with x as (
 select level as lvl, 'ABC'||level as txt
 from dual
 connect by level < 10
)
select 
 case when grouping(txt) > 0 then 'SUM' else txt end as txt, 
 sum(lvl) as count
from x
group by rollup ((txt, lvl))

image.pngI would like something like this:
image.pngwithout repeating the query and using a union all solution....
thx.

This post has been answered by Solomon Yakobson on Sep 5 2022
Jump to Answer
Comments
Post Details
Added on Sep 4 2022
8 comments
101 views