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 |
jfm
Posting Yak Master
145 Posts |
Posted - 2013-05-09 : 06:21:57
|
Hi there, I need to select the distinct ID's that I have in Col_Id and SUM their balance from col_Balance and table1Any tip? Thanks |
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2013-05-09 : 06:26:17
|
is this??select id,sum(col_balance) from tablegroup by idmohammad.javeed.ahmed@gmail.com |
 |
|
jfm
Posting Yak Master
145 Posts |
Posted - 2013-05-09 : 06:30:11
|
Nope. As I have duplicates I will need to use unique or distinct in the query.. I need not to take into account the exiting duplicates because the balance in the extraction is wrong due to this ID's duplicatedAny idea?quote: Originally posted by ahmeds08 is this??select id,sum(col_balance) from tablegroup by idmohammad.javeed.ahmed@gmail.com
|
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-09 : 07:01:27
|
do you mean this?select id,sum(case when rn=1 then col_balance else 0 end) from (select row_number() over (partition by id order by id) as rn,*from table)tgroup by id ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2013-05-09 : 10:51:53
|
http://www.sqlservercentral.com/articles/Best+Practices/61537/http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
|
|