序言

测试数据

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

SQL Server 基础:Case两种用法

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

SQL Server 基础:Case两种用法

资料

 

相关文章:

  • 2022-12-23
  • 2021-06-02
  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-11
  • 2022-12-23
  • 2021-07-15
相关资源
相似解决方案