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 @   小小白兔兔  阅读(19)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
历史上的今天:
2021-03-10 Ubuntu 18.04配置及Linux库文件下载地址
点击右上角即可分享
微信分享提示