举例:
原数据库表sys_oper_log大概显示
case when then else end语句用法--具体sql如下
select DATE_FORMAT(oper_time,'%Y-%m') yearMonth,
sum(case when business_type=1 then 1 else 0 end) addOps,
sum(case when business_type=2 then 1 else 0 end) updateOps,
sum(case when business_type=3 then 1 else 0 end) deleteOps from sys_oper_log t
where year(oper_time)=2019 group by
DATE_FORMAT(oper_time,'%Y-%m')
case when then else end语句用法的具体实现结果