您的位置:首页 > 数据库

SQL中CASE的用法

2014-09-24 14:02 288 查看
创建一张测试表
<span style="font-size:18px;">create table test9009
(
id int identity(1,1) primary key,
score int
)

insert into test9009 values(500)
insert into test9009 values(200)
insert into test9009 values(1000)
insert into test9009 values(1500)
insert into test9009 values(300)
insert into test9009 values(2000)
insert into test9009 values(1520)
insert into test9009 values(3000)
insert into test9009 values(35000)</span>
<span style="font-size:18px;">select
*,
case
when score<500 then '列兵'
when score>=500 and score<=1500 then '上等兵'
else '上士'
end as 等级
from test9009</span>

显示结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息