标签: sql
如何在SQL中将这些结果显示在一行?
答案 0 :(得分:1)
您可以使用GROUP BY执行此操作:
SELECT school_id, school_name, grade, SUM(CASE WHEN Gender='F' THEN 1 ELSE 0 END) as female, SUM(CASE WHEN Gender='M' THEN 1 ELSE 0 END) as male FROM yourtable GROUP BY school_id, school_name, grade;