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 |
|
pushp82
Yak Posting Veteran
83 Posts |
Posted - 2012-03-14 : 11:44:51
|
| Hi Guys,My table structre is as below:ID Name Amount Sno 1 sdfdsf 1000.00 142 ABC 10000.00 143 kfkjdn 5000.00 154 hgfhs 500.00 19I need to sum the Amount for each Sno in next column as below:ID Name Amount Sno Sum1 sdfdsf 1000.00 14 2000.002 ABC 1000.00 14 2000.003 kfkjdn 5000.00 15 5500.004 hgfhs 500.00 15 5500.00How to do this in one query??Please help!Pushp |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-03-14 : 12:00:23
|
selectID,Name,Amount,Sno,sum(Amount) over (partition by Sno) as sumAmountfrom table No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-14 : 12:56:22
|
| how did Sno 19 merge with 15 row? is that a typo?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
pushp82
Yak Posting Veteran
83 Posts |
Posted - 2012-03-15 : 09:43:43
|
hey vishak that was a typo exactly...quote: Originally posted by visakh16 how did Sno 19 merge with 15 row? is that a typo?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
 |
|
|
pushp82
Yak Posting Veteran
83 Posts |
Posted - 2012-03-15 : 09:45:06
|
owesome.. thati's gr8 thanks...quote: Originally posted by webfred selectID,Name,Amount,Sno,sum(Amount) over (partition by Sno) as sumAmountfrom table No, you're never too old to Yak'n'Roll if you're too young to die.
|
 |
|
|
|
|
|