Solved

cumulative options in SQL query with Count function

Posted on 2004-07-30
1
1,219 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

829 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