MySQL分支判断

b053a543-cdcf-4645-a0da-fad153b99360

if(1,2,3)
判断1的真假
真,运算2
假,运算3

case
when 条件1(由字段组成的条件) then …
when 条件2 then …
else …
end

case 数据(字段)
when 值1 then …
when 值2 then …
else …
end

举例

select
employee_id,first_name,salary,
case
when salary>=15000 then '富豪'
when salary>=8000 then '小康'
when salary>=3000 then '温饱'
else '平民'
end rank
from employees
order by salary desc;

select
employee_id,first_name,salary,
case department_id
when 90 then '90部门'
when 100 then '100部门'
else '其他部门'
end dp
from employees
order by dp;
posted @ 2023-03-10 22:28  小小白兔兔  阅读(16)  评论(0编辑  收藏  举报  来源