case when xxx then xxx when xxx then xxx … else xxx end(case when xxx then xxx when xxx then xxx … else xxx end)

mysql查询语句中的条件判断 case when then else end

1 若是真假判断

select case gender when 1 then ‘男’ when 0 then ‘女’ else ‘未知’ end from tt

2 若是范围划分判断

select case when score < 60 then ‘不及格’when score < 90 then ‘中等’when score >= 90 then ‘优秀’else xxxend from t1

或者

select case when play_times < 100 then ‘少’when play_times > 500 and play_times < 1000 then ‘有点多了’when play_times < 3000 then ‘中’when play_times < 5000 then ‘多’else ‘火爆’end as ‘视频播放次数’from video;

————————

Case when then else end in MySQL query statement

1. If it is true or false, judge

select case gender when 1 then ‘男’ when 0 then ‘女’ else ‘未知’ end from tt

2. Judgment of range Division

select case when score < 60 then ‘不及格’when score < 90 then ‘中等’when score >= 90 then ‘优秀’else xxxend from t1

perhaps

select case when play_times < 100 then ‘少’when play_times > 500 and play_times < 1000 then ‘有点多了’when play_times < 3000 then ‘中’when play_times < 5000 then ‘多’else ‘火爆’end as ‘视频播放次数’from video;