我有一个包含三列Stud_Name,Operated_By,Status
的表Stud_Name Operated_By Status Sri 1 Aprove Manoj 1 Aprove Ranjan 1 Rejected Arif 3 Rejected
我想要以下结果:
Operated_By Aprove Rejected 1 2 1 3 0 1
提前致谢
答案 0 :(得分:4)
SELECT Operated_By,
SUM(CASE WHEN Status = 'Aprove' THEN 1 ELSE 0 END) AS Aprove,
SUM(CASE WHEN Status = 'Rejected' THEN 1 ELSE 0 END) AS Rejected
FROM MyTable
GROUP BY Operated_By