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 |
|
poornimajayan
Starting Member
3 Posts |
Posted - 2008-09-10 : 02:23:48
|
| Hi all, I need a query likeName Age MGR salaryA 10 A 10B 20 B 20A 10 A 5s 30 D 4I want the output as follows.Since A isduplicating, I want only one record for A andthe salary for it should be the sum of salary for allrecords of A.A 10 A 15B 20 B 20S 30 D 4Can u give me a query? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-09-10 : 02:26:32
|
[code]select Name, Age, MGR, sum(salary)from yourtableGroup by Name, Age, MGR[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
poornimajayan
Starting Member
3 Posts |
Posted - 2008-09-10 : 05:39:07
|
| Thanks Khtan...But My actual requirement is like this:I have 10 columns A,B,..J. I want to select all columns from this table and (if value of column E=%CCT% and if duplicates are there(based on keys A,B,C) then I need to display one record only;but its column H should be a sum of all the records).Hope you got. Then I cannot use this as I need to keep all 10 records in group by,which won't make row as distinct Thanks, Poornima |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-09-10 : 05:40:47
|
Post your table DDL, sample data and expected result KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
poornimajayan
Starting Member
3 Posts |
Posted - 2008-09-10 : 21:02:19
|
| Suppose if I have 10 columns in a table, I want to list all 10 columns grouped by first 3 columns.So I got it done as select Name, Age,MGR,max(X),max(Y),max(Z), sum(salary)from yourtableGroup by Name, Age, MGR |
 |
|
|
|
|
|
|
|