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.
| 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 Requests10/4 109/4 87/4 56/4 15/4 14/4 13/4 0on 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 ranalkresult should be:Date Requests10/4 109/4 87/4 56/4 15/4 14/4 13/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. |
 |
|
|
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 requetsINTO #temp1FROM tb_requests tpgroup by CONVERT(VARCHAR(10),tp.created,111)ORDER BY 1 DESC |
 |
|
|
|
|
|