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

 

posted @ 2022-01-14 19:20  江湖凶险  阅读(101)  评论(0编辑  收藏  举报