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 |
winchmore
Starting Member
1 Post |
Posted - 2014-10-16 : 19:03:15
|
Hi i got a group by query with the result:Select Department ,gender , count(EmpID) as totalcount from employeegroup by Department ,genderDepartment gender totalcountA M 5A F 5B M 2B F 3C F 10what i would like is :Department M F A 5 5B 2 3C 10Any help will be great :) |
|
nagino
Yak Posting Veteran
75 Posts |
Posted - 2014-10-16 : 20:50:34
|
like following?SELECT Department, M, F FROM SOURCEPIVOT( COUNT(EmpID) FOR gender IN (M, F)) AS PVT -------------------------------------From JapanSorry, my English ability is limited. |
|
|
em172967
Starting Member
10 Posts |
Posted - 2014-10-17 : 11:04:25
|
I would do Select Department, Case when gender = 'M' then count(empid) else 0 end as M_Count, Case when gender = 'F' then count(empid) else 0 end as F_countfrom my tablequote: Originally posted by winchmore Hi i got a group by query with the result:Select Department ,gender , count(EmpID) as totalcount from employeegroup by Department ,genderDepartment gender totalcountA M 5A F 5B M 2B F 3C F 10what i would like is :Department M F A 5 5B 2 3C 10Any help will be great :)
|
|
|
|
|
|