创建一张测试表
<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>
显示结果: