select 中使用case when
说明:select 中 结合 聚合函数、group 使用case when
语法:case when $condition then $deal else $deal end alias
使用:SELECT gender, sum(case when sex = 1 then 1 else 0 end) as men ,sum(case when sex = 2 then 1 else 0 end ) as women FROM user GROUP BY gender。
注意:分类汇总要和 group by 结合使用