需求
表格结构希望统计的结果如下代码实现
SELECT a.name,SUM(CASE WHEN a.TYPE_ = '在校' THEN 1 ELSE 0 END) AS '在校次数',SUM(CASE WHEN a.TYPE_ = '在家' THEN 1 ELSE 0 END) AS ‘在家次数’FROM table a GROUP BY a.name;
时间:2021-02-08 23:06:20
SELECT a.name,SUM(CASE WHEN a.TYPE_ = '在校' THEN 1 ELSE 0 END) AS '在校次数',SUM(CASE WHEN a.TYPE_ = '在家' THEN 1 ELSE 0 END) AS ‘在家次数’FROM table a GROUP BY a.name;