我有以下内容:
Select Coalesce(Other,Industry) Ind from registration
问题是Other
可以是空字符串或NULL
。我如何coalesce
工作,以便如果Other
是空字符串,Coalesce
仍然返回Industry
?
Answers:
您也可以使用捷径知道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