case when xxx then xxx when xxx then xxx ... else xxx end
mysql查询语句中的条件判断 case when then else end
1)case等值分析
select case sex when 1 then '男' when 0 then '女' else '没有设置' end as '性别' from xxx
2)case范围分析
select case when play_times < 500 then '少' when play_times >= 500 and play_times < 1000 then '多' when play_times > 1000 then '较多' else '火爆' end as '播放次数' from xxx;
3)update根据不同条件更新
update xxx set play_times = case when play_times < 500 then play_times - 1 when play_times >= 500 then play_times + 1 else play_times + 1 end