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 |
|
rum23
Yak Posting Veteran
77 Posts |
Posted - 2009-06-11 : 08:13:51
|
| ID2 Year Cost TimeStamp ID125 2006 749411.76 0x0000000000008CC0 1225 2007 1001960.78 0x0000000000008CC1 1225 2008 1111705.88 0x0000000000008CC2 1225 2009 1001960.78 0x0000000000008CC3 1225 2010 1001960.78 0x0000000000008CC4 1225 2011 1002598.43 0x0000000000008CC5 1225 2012 1008661.42 0x0000000000008CC6 1225 2013 228740.17 0x0000000000008CC7 1226 2006 12678.76 0x0000000000008CC9 1226 2007 1001960.78 0x0000000000008CCA 1226 2008 1004705.88 0x0000000000008CCB 1226 2009 1001960.78 0x0000000000008CCC 1226 2010 1001960.78 0x0000000000008CCD 1226 2011 1002598.43 0x0000000000008CCE 1226 2012 1008661.42 0x0000000000008CCF 1226 2013 228740.17 0x0000000000008CD0 12What is the SQL to get the following output? I want to sum the Cost by Year. Eg. For Year 2008, the cost should be 1004705.88 + 1111705.88The output should be like this.ID1 Year Cost12 2006 749411.76 + 12678.7612 2007 XXXXX12 2008 1004705.88 + 1111705.88 and so forth. |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2009-06-11 : 08:27:43
|
Simply this...... ?SELECT [Id1] , [Year] , SUM([cost])FROM <theTable>GROUP BY [Id1] , [Year]ORDER BY [Year] ASC Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
|
|
|