判断是否为null:
select case when 字段名 is null then '自定义值' else 字段名 end as "别名"
from table
判断 int 类型:
select case
when 字段名 =
条件 then 自定义值1
when 字段名 = 条件 then 自定义值1
else
自定义值2 end as "别名"
from table
判断字符串:
select case 字段名
when '条件' then '自定义值' else
'自定义值2' end as "别名"
from table
select case when 字段名
= '条件' then '自定义值1'
else '自定义值2' end
as "别名"
from table
本文介绍了如何使用 SQL 中的 Case 语句进行条件判断,包括处理 null 值、整型和字符串类型的条件判断场景,并提供了实际的 SQL 代码示例。
1809

被折叠的 条评论
为什么被折叠?



