sql条件查询case语句

2022/7/1 2:21:07

本文主要是介绍sql条件查询case语句,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

case语句

1、语法:select * ,
case
when then
end
from 表名;

--查询所有员工信息,添加一列,显示生肖
select *,
CASE
when year(PeopleBirth)%12=4 then '鼠'
when year(PeopleBirth)%12=5 then '牛'
when year(PeopleBirth)%12=6then '虎'
when year(PeopleBirth)%12=7 then '兔'
when year(PeopleBirth)%12=8 then '龙'
when year(PeopleBirth)%12=9 then '蛇'
when year(PeopleBirth)%12=10 then '马'
when year(PeopleBirth)%12=11 then '羊'
when year(PeopleBirth)%12=12 then '猴'
when year(PeopleBirth)%12=1 then '鸡'
when year(PeopleBirth)%12=2 then '狗'
when year(PeopleBirth)%12=3 then '猪'
 else ''
end 生肖
from people



这篇关于sql条件查询case语句的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程