【发布时间】:2020-02-14 11:46:45
【问题描述】:
当我编写一个 case 语句来比较表中的值时,它与 null 变量不一致。它认为它们是不同的(注意:col1 是一个字符字段)。
select a.id,
a.col1 as a_col1,
b.col1 as b.col1,
case when a.col1=b.col1 then 0 else 1 end as chk_col1
from tablea a,
tableb b
where a.id=b.id;
... 当两个 col1 都为空时,chk_col1 始终为 0。我试过了
coalesce(a.col1,'null') as coalesce(b.col1,'null')
但这也不起作用。它仍然为 chk_col1 返回 1。
【问题讨论】:
标签: sql postgresql null compare coalesce