Solved

cumulative options in SQL query with Count function

Posted on 2004-07-30
1
1,220 Views
Last Modified: 2012-06-21
I like to create one query which will produce cumulative result also

my query

select substring(access_time_, 0, 11) "Date", count(*)"Total Downloads"
from tab1  where iface_type='web_server' and access_time_ > 
'2004-07-14 00:00:00.000' and access_time < '2004-07-29 23:59:59.999'and msisdn
not in (select number from excluded)
group by substring(access_time, 0, 11) order by  substring(access_time, 0, 11) asc

Above query will display following :

2004-07-20          2      
2004-07-27         6      

Now I would like to add cumulative result also : example
Date                    total          cumulative
2004-07-20          2                2
2004-07-27         6                8

is this possiable

Arvind
0
Comment
Question by:arvind
1 Comment
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 50 total points
ID: 11674456
select a.[date],a.[Total downloads],sum(b.[total downloads]) as cum
from (
select substring(access_time_, 0, 11) "Date", count(*)"Total Downloads"
from tab1  where iface_type='web_server' and access_time_ >
'2004-07-14 00:00:00.000' and access_time < '2004-07-29 23:59:59.999'and msisdn
not in (select number from excluded)
group by substring(access_time, 0, 11))
as A
Inner Join
 (
select substring(access_time_, 0, 11) "Date", count(*)"Total Downloads"
from tab1  where iface_type='web_server' and access_time_ >
'2004-07-14 00:00:00.000' and access_time < '2004-07-29 23:59:59.999'and msisdn
not in (select number from excluded)
group by substring(access_time, 0, 11))
as B
on A.[Date] >= b.[Date]
group by a.[date],a.[Total downloads]
 order by  A.[date] asc
0

Featured Post

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question