您的位置:首页 > 数据库

SQL利用Case When Then end多条件判断

2014-04-02 11:21 309 查看
case,when有两种用法

第一种:case的简单用法

select
case aname
when '郑' then '名字是'郑'就显示对应的结果'
when '22' then '名字是22就显示对应的结果'
else '其他的结果显示else'
end
from admininfo;

第二种:case函数的用法

select aid,atel,
case
when aname='郑' then '名字是‘郑’就显示对应的结果'
when aname='22' then '名字是’22‘就显示对应的结果'
else '其他的结果显示else'
end as aname
from admininfo;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sql case then when end