我有以下内容:
Select Coalesce(Other,Industry) Ind from registration
问题是它Other
可以是一个空字符串或NULL
. 我如何开始coalesce
工作,如果Other
是一个空字符串,Coalesce
仍然返回Industry
?
我有以下内容:
Select Coalesce(Other,Industry) Ind from registration
问题是它Other
可以是一个空字符串或NULL
. 我如何开始coalesce
工作,如果Other
是一个空字符串,Coalesce
仍然返回Industry
?
使用CASE
表达式或NULLIF
:
SELECT COALESCE(NULLIF(Other,''),Industry) Ind FROM registration
试试这个
Select Coalesce(nullif(Other,''),Industry) Ind from registration
NULL <> ''
您也可以使用不会评估为TRUE
...的捷径知道
CASE WHEN other <> '' THEN other ELSE industry END
然后逻辑如下...
CASE WHEN 'fubar' <> '' THEN other ELSE industry END
=> CASE WHEN true THEN other ELSE industry END
=>other
CASE WHEN '' <> '' THEN other ELSE industry END
=> CASE WHEN false THEN other ELSE industry END
=>industry
CASE WHEN NULL <> '' THEN other ELSE industry END
=> CASE WHEN NULL THEN other ELSE industry END
=>industry