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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to use SUM

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 14
2 ABC 10000.00 14
3 kfkjdn 5000.00 15
4 hgfhs 500.00 19

I need to sum the Amount for each Sno in next column as below:

ID Name Amount Sno Sum
1 sdfdsf 1000.00 14 2000.00
2 ABC 1000.00 14 2000.00
3 kfkjdn 5000.00 15 5500.00
4 hgfhs 500.00 15 5500.00

How to do this in one query??
Please help!
Pushp

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-14 : 12:00:23
select
ID,
Name,
Amount,
Sno,
sum(Amount) over (partition by Sno) as sumAmount
from table



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

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 MVP
http://visakhm.blogspot.com/



Go to Top of Page

pushp82
Yak Posting Veteran

83 Posts

Posted - 2012-03-15 : 09:45:06
owesome.. thati's gr8 thanks...
quote:
Originally posted by webfred

select
ID,
Name,
Amount,
Sno,
sum(Amount) over (partition by Sno) as sumAmount
from table



No, you're never too old to Yak'n'Roll if you're too young to die.

Go to Top of Page
   

- Advertisement -