Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Help needed

Author  Topic 

sheikh81
Starting Member

3 Posts

Posted - 2011-09-27 : 12:58:56
I need help with running total query in oracle.

When I execute the query below:

select count(order_id), platform_id from itc_com_order_header
group by platform_id

Output:
COUNT(ORDER_ID) PLATFORM_ID
8 CC
5 GC
4520 GT

I want something like

COUNT(ORDER_ID) PLATFORM_ID Total
8 CC 8
5 GC 13
4520 GT 4533

Thanks in advance.


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-27 : 13:05:07
[code]
;with cte (cnt,platform_id)
as
(
select count(order_id) , platform_id from itc_com_order_header
group by platform_id
)

select c.*,c1.runcnt
from cte c
cross apply (select sum(cnt) as runcnt
from cte
where platform_id<=c.platform_id)c1
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-09-27 : 13:09:02
"in oracle"

This is a Microsoft SQL Server forum, so you may not find people here who have good knowledge or Oracle I'm afraid.
Go to Top of Page

sheikh81
Starting Member

3 Posts

Posted - 2011-09-27 : 13:09:36
visakh16; thanks for such a quick response, I tried to execute this and getting "missing keyword" toad error on the cross apply.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-27 : 13:13:05
sorry didnt realise you're on oracle. if yes, this is wrong forum to post. As Kristen suggested post in some Oracle forums like www.dbforums.com

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sheikh81
Starting Member

3 Posts

Posted - 2011-09-27 : 13:19:17
Thank You all :)
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-09-27 : 13:24:54
@Visakh : I was getting ready to eat my hat if that had just run, as-is, on Oracle!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-27 : 13:27:18
quote:
Originally posted by Kristen

@Visakh : I was getting ready to eat my hat if that had just run, as-is, on Oracle!




------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -