Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

cumulative options in SQL query with Count function

Posted on 2004-07-30
1
Medium Priority
?
1,227 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 200 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

916 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