【查询】Case

测试数据

 

用法一:   等值判断(当于switch case )

 

Select S#, C#, C#=
(
    case C#
        when 1 then '语文'
        when 2 then '数学'
        when 3 then '英语'
        when 4 then '思修'
    end
) 
from sc

 

用法二: 条件判断(相当于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

 

 

 

 

 

posted @ 2019-12-12 16:09  黑涩小豆  阅读(112)  评论(0)    收藏  举报