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 |
|
goligol
Posting Yak Master
128 Posts |
Posted - 2011-10-17 : 11:23:22
|
| Hi,I have the following table,id dist MM YYYYMM val1 val2 val3 val4 val545 39 10 200710 0 0 0 43730 3053045 39 11 200711 890830 890830 4883 934560 92136045 39 12 200712 0 0 0 934560 92136046 27 6 200706 496513 496513 1898 496513 49651346 27 7 200707 0 0 0 496513 496513I want to generate a view which for example for id 45, sum up the val1, val2, val3, val4, val5 for the months of 10,11,and12. and it does the something for id 46 and so on, the length of this table is too big so I need a query to go through different id and look at the different MM (months) to sum up them.Thank you |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-17 : 11:28:34
|
| [code]SELECT id,SUM(val1) as val1,SUM(val2) as val2,....SUM(val5) AS val5FROM Tblwhere [MM] IN (10,11,12)GROUP BY id[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|