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 |
|
rpieszak
Starting Member
11 Posts |
Posted - 2005-06-10 : 13:26:08
|
| Greetings all,This is an example of the hourly data that I have...Timestamp__________Value3/17/2005 00:00______53/17/2005 01:00______73/17/2005 02:00______11...6/9/2005 21:00_______46/9/2005 22:00_______126/9/2005 23:00_______15...but this is the data format that I need...Timestamp__________Value_______Sum Total3/17/2005 00:00______5__________53/17/2005 01:00______7__________123/17/2005 02:00______11_________23...6/9/2005 21:00_______4__________292056/9/2005 22:00_______12_________292176/9/2005 23:00_______15_________29232The challenge is to be able to do this without having to loop through the records and keep a running total. Is it possible to do this in one query (possibly with subqueries)?Any questions, let me know.Thanks in advance for any helpRyan |
|
|
mpetanovitch
Yak Posting Veteran
52 Posts |
Posted - 2005-06-10 : 13:34:17
|
| [code][code]CREATE TABLE #yak (yak_date datetime, yak_value int)INSERT INTO #yakVALUES ('3/17/2005 00:00', 5)INSERT INTO #yakVALUES ('3/17/2005 01:00', 7)INSERT INTO #yakVALUES ('3/17/2005 02:00', 11)INSERT INTO #yakVALUES ('6/9/2005 21:00', 4)INSERT INTO #yakVALUES ('6/9/2005 22:00', 12)INSERT INTO #yakVALUES ('6/9/2005 23:00', 15)SELECT y1.yak_date, y1.yak_value, SUM (y2.yak_value) AS yak_sumFROM #yak y1 INNER JOIN #yak y2 ON y1.yak_date >= y2.yak_dateGROUP BY y1.yak_date, y1.yak_valueORDER BY y1.yak_date[/code][/code]Mike Petanovitch |
 |
|
|
vivek.kumargupta
Starting Member
45 Posts |
Posted - 2005-06-13 : 06:15:47
|
| select timestamp,value,(select sum(value)from your_table_name where t.timestamp<=v )as sumtotal from your_table_name tgroup by timestamp,valuehope this solves ur problem ......??Thanks, Vivek |
 |
|
|
vivek.kumargupta
Starting Member
45 Posts |
Posted - 2005-06-13 : 06:16:38
|
| A li'lmodififcation select timestamp,value,(select sum(value)from your_table_name where t.timestamp<=timestamp )as sumtotal from your_table_name tgroup by timestamp,valuewat do ya say ??Thanks, Vivek |
 |
|
|
|
|
|
|
|