--相当于C#中的if-else 根据levle列的值来判断自定义列显示的内容
--要求then后面的数据类型必须一致

select * ,头衔=case
when [levle]=1 then '菜鸟'
when [levle]=2 then '老鸟'
when [levle]=3 then '大师'
else '骨灰级'
end
from [user];

--相当于C#中的switch

select * ,头衔=case [levle]
when 1 then '菜鸟'
when 2 then '老鸟'
when 3 then '大师'
else '骨灰级'
end
from [user];

select * from tblscore;

select tScoreId,tSId,tEnglish,等级=case
when tEnglish>=95 then '优'
when tEnglish>=80 then '良'
when tEnglish>=70 then '差'
when tEnglish<60 then '不良格'
else '不良格'
end
from dbo.TblScore

相关文章:

  • 2021-08-21
  • 2022-01-16
  • 2021-05-06
  • 2022-12-23
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
猜你喜欢
  • 2021-05-25
  • 2022-12-23
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
相关资源
相似解决方案