请教一条汇总的SQL该如何写
有一张表A记录了每个人负责的项目状态,字段为
Lead_Name, Project_Name, Project_Status
Project_Status字段中分别含有的状态是Pending Ongoing Open
想写一条SQL 可以生成一张表,将每个Lead所负责的Project的状态的数量列出来
例如:
Lead_Name Ongoing Open Pending
Zhang 8 3 2
Wang 4 2 3
Sun 12 4 7
现在只能想到这么写
SELECT lead_name, count([project_status])as Ongoing FROM A where Project_Status='Ongoing' group by project_lead
要怎么改动一下才能实现我的要求,请大家指教一下啊 多谢 多谢
------解决方案--------------------case when
------解决方案--------------------select Lead_Name,Pending=SUM(case when Project_Status='Pending' then 1 else 0 end)
,Ongoing=SUM(case when Project_Status='Ongoing' then 1 else 0 end)
,[Open]=SUM(case when Project_Status='Open' then 1 else 0 end)
from tb
group by Lead_Name