case when用法

1.>=

case
when score>=80 then ‘优秀’
when score<80 and score>=60 then ‘良好’
else ‘不及格’
end as comment

select 
case 
when score>=80 then '优秀'
when score<80 and score>=60  then '良好'
else '不及格' 
end as comment
from (select 80 as score) t

2.=

case score
when 80 then ‘优秀’
when 60 then ‘良好’
else ‘不及格’
end as comment
或者
case
when score=80 then ‘优秀’
when score=60 then ‘良好’
else ‘不及格’
end as comment

select 
case  score
when 80 then '优秀'
when  60   then '良好'
else '不及格'
end as comment
from (select 80 as score) t
上一篇:Django——实现评论功能(包括评论回复)


下一篇:NestJS下的CQRS实现 - Command、Event