Solved

cumulative options in SQL query with Count function

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now