Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Can rollup help in this situation?
On 30 Jul 2004 05:45:19 -0700, laredotornado_at_zipmail.com (D. Alvarado) wrote:
>Hi,
> I have a table that records number of new registrants in a day.
>Some records may look like
>
>DAY NUM_REGISTRANTS
>--- ---------------
>1 10
>2 5
>3 8
>
>I would like to create a SELECT statement such that I select the
>number of registrants per day, and the total number of registrants up
>to that point. Can I do that with SQL somehow? Ideally, a SELECT of
>the above data would yield
>
>DAY NUM_REGISTRANTS TOTAL_REGISTRANTS
>--- --------------- -----------------
>1 10 10
>2 5 15
>3 8 23
>
>Thanks for any advice, - Dave
SQL> create table day_registration_total 2 (
3 day number not null, 4 num_registrants number not null, 5 constraint day_registration_total_pk 6 primary key (day)
Table created.
SQL> insert into day_registration_total values (1, 10);
1 row created.
SQL> insert into day_registration_total values (2, 5);
1 row created.
SQL> insert into day_registration_total values (3, 8);
1 row created.
SQL> select day,
2 num_registrants, 3 sum(num_registrants) over ( 4 order by day 5 rows unbounded preceding 6 ) total_registrants
DAY NUM_REGISTRANTS TOTAL_REGISTRANTS
---------- --------------- ----------------- 1 10 10 2 5 15 3 8 23
-- Andy Hassall <andy_at_andyh.co.uk> / Space: disk usage analysis tool http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/spaceReceived on Fri Jul 30 2004 - 12:51:23 CDT
![]() |
![]() |