2013-07-01 72 views
1

如何獲得GROUPBY結果作爲列名集團通過結果作爲單獨的列名

如果員工表是那裏,當我們使用來自員工隊伍

SELECT COUNT(*)按性別;讓我爲

enter image description here

,但我需要他們作爲男欄|女性|無

+1

考慮在應用程序級別(例如,用PHP位的) – Strawberry

回答

6
select sum(case when gender = 'Male' then 1 else 0 end) as 'Male', 
sum(case when gender = 'Female' then 1 else 0 end) as 'Female', 
sum(case when gender not in ('Male','Female') or gender is null then 1 else 0 end) as 'None' 
from staff; 
+0

這是super..thanks Bill..it工作得非常好地處理數據顯示的問題.. – sakar