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 |
|
sqldbaa
Starting Member
32 Posts |
Posted - 2009-09-22 : 06:39:58
|
| Hi ,I have a table with the below fieldsname total -------------------------------------------------- ----------- a 0b 1a 2c 3a 5a 11c 4b 2c 4I have to retrieve the rows whose sum(total) > 10 grouped by nameThe output needs to be shown as belowname total -------------------------------------------------- ----------- a 0a 2a 5a 11c 4c 4c 3Can anyone let me know the query for this. |
|
|
sumitbatra1981
Starting Member
17 Posts |
Posted - 2009-09-22 : 06:42:00
|
| select * from table group by name having sum(total)>10Regards,Sumit BatraSoftware Engineer |
 |
|
|
sqldbaa
Starting Member
32 Posts |
Posted - 2009-09-22 : 07:10:21
|
| This query fails as in group by we have only name, but in select it is '*'. All in select statment, should be in group by,. But if total is added to group by , then output is grouped by both name and total.I need the output grouped by name and sum(toatl)>10 |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-09-22 : 07:29:29
|
| Do you mean this?SELECT t2.*from ( select name,[total] = sum(total) from [table] group by name having sum(total) > 10 ) t1inner join @table t2 on t1.name = t2.nameJimEveryday I learn something that somebody else already knew |
 |
|
|
sqldbaa
Starting Member
32 Posts |
Posted - 2009-09-22 : 07:43:26
|
| Thanks for the reply. I tried with another option using, sub query which also gives the resultselect * from [table] where name in ( select name from [table] group by name having sum(total)>10) |
 |
|
|
|
|
|