您的位置:首页 > 数据库

SQL Server 基础:Case两种用法

2016-03-11 09:27 525 查看
测试数据





1).等值判断->相当于switch case

select S#,C#,C#=(
case C#
when 1 then '语文'
when 2 then '数学'
when 3 then '英语'
when 4 then '选修'
end
)
from Sc




2)条件判断->相当于if else if else

select S#,score,score=(
case
when score<60 then '差'
when score between 60 and 80  then '中'
when score between 80 and 90  then '良'
when score between 90 and 100  then '优'
else '缺考'
end
)
from Sc




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