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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Count + Sum

Author  Topic 

ranalk
Starting Member

49 Posts

Posted - 2010-04-25 : 09:50:46
Hi,

I need your help on how to count + sum.
The case is counting some value per day (let's say X) and adding the amount of the day before to the current day.
result should be:
Date Requests
10/4 10
9/4 8
7/4 5
6/4 1
5/4 1
4/4 1
3/4 0

on the 3/4 there were nor requests at all, on 4/4 there was 1 request. on the 5/4 and 6/4 there were no requests at all, on the 7/4 there were 4 requests (total 4+1=5)

Thanks!

DBA in the making
Aged Yak Warrior

638 Posts

Posted - 2010-04-25 : 09:54:52
quote:
Originally posted by ranalk
result should be:
Date Requests
10/4 10
9/4 8
7/4 5
6/4 1
5/4 1
4/4 1
3/4 0



If that's your expected result set, then what does the source data look like?

------------------------------------------------------------------------------------
Any and all code contained within this post comes with a 100% money back guarantee.
Go to Top of Page

ranalk
Starting Member

49 Posts

Posted - 2010-04-25 : 10:05:14
The idea is on how to do count and sum the previous result.
SELECT
CONVERT(VARCHAR(10),
tp.created,111) AS Date,count(CONVERT(VARCHAR(10)
,tp.created,111)) AS requets
INTO #temp1
FROM tb_requests tp
group by CONVERT(VARCHAR(10),tp.created,111)
ORDER BY 1 DESC
Go to Top of Page
   

- Advertisement -