select case status when 1 then ‘成功‘ when 2 then ‘失败‘ else ‘其他‘ end from user
1,case后面紧跟要被作为判断的字段
2,when后面跟判断条件
3,then后面跟结果
4,else相当于default
5,end是语句结束语
如:
select account 账号, case register_channel when 1 then ‘直播‘ when 2 then ‘直播本站‘ when 3 then ‘直播本站PC‘ when 4 then ‘直播本站H5‘ when 5 then ‘直播Android‘ when 6 then ‘直播IOS‘ else ‘其他‘ end 注册渠道, case platform when 1 then ‘pc‘ when 2 then ‘h5‘ when 3 then ‘ios‘ when 4 then ‘android‘ when 5 then ‘cms‘ when 6 then ‘system‘ else ‘其他‘ end 平台, register_time 注册时间 from users;
Mysql的switch语句
原文地址:https://www.cnblogs.com/stronger-xsw/p/13439504.html