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!

SQL rollup count every day

vijzApr 19 2018 — edited Apr 19 2018

Below is the sample code for illustration:

with val (id,dt) as (

select 1, TO_TIMESTAMP('2017/03/22 10:13:18', 'YYYY/MM/DD HH24:MI:SS') from dual union all

select 2, TO_TIMESTAMP('2017/03/22 10:13:18', 'YYYY/MM/DD HH24:MI:SS') from dual union all

select 3, TO_TIMESTAMP('2017/03/22 12:13:18', 'YYYY/MM/DD HH24:MI:SS') from dual union all

select 4, TO_TIMESTAMP('2017/03/22 12:13:18', 'YYYY/MM/DD HH24:MI:SS') from dual union all

select 5, TO_TIMESTAMP('2017/03/22 15:13:18', 'YYYY/MM/DD HH24:MI:SS') from dual union all

select 6, TO_TIMESTAMP('2017/03/23 10:13:18', 'YYYY/MM/DD HH24:MI:SS') from dual union all

select 7, TO_TIMESTAMP('2017/03/23 11:13:18', 'YYYY/MM/DD HH24:MI:SS') from dual union all

select 8, TO_TIMESTAMP('2017/03/23 11:13:18', 'YYYY/MM/DD HH24:MI:SS') from dual union all

select 9, TO_TIMESTAMP('2017/03/23 14:13:18', 'YYYY/MM/DD HH24:MI:SS') from dual union all

select 10, TO_TIMESTAMP('2017/03/23 14:13:18', 'YYYY/MM/DD HH24:MI:SS') from dual

) select nvl(to_char(trunc(dt, 'HH'), 'DD-MON-RR HH24'), 'SUM = ') AS hourly_date,count(id) from val

group by rollup (trunc(dt, 'HH'))

order by 1

Below is the output for above SQL:

pastedImage_8.png

Is there any way to produce Totals for each day, rather than grand total

This post has been answered by mathguy on Apr 19 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 17 2018
Added on Apr 19 2018
3 comments
1,145 views