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 |
|
sent_sara
Constraint Violating Yak Guru
377 Posts |
Posted - 2006-12-12 : 22:21:37
|
| hi fyi,table-gworker idno unit sexrab4012 30 mrab4013 25 frab4014 30 mrab4015 30 fthe result should be:unit m f30 2 125 0 1 select unit,count(sex)from gworker group by sex.it works but it not shows like above output:how to form a query using group by???????? |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-12-12 : 22:41:32
|
| [code]select unit, M = sum(case when sex = 'm' then 1 else 0 end), F = sum(case when sex = 'f' then 1 else 0 end)from gworkergroup by unitorder by unit[/code]CODO ERGO SUM |
 |
|
|
|
|
|