SQL Server 基础:Case两种用法

序言

测试数据

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

资料

 

原文地址:https://www.cnblogs.com/cnki/p/5264321.html