NULL比较,取2
我有一个子查询,在 WHERE 部分中使用:
A.column <> B.column
不幸的是,如果 A.column 或 B.column 为 NULL,则它不起作用。因此,我将其转换为:
((A.column <> B.column) OR ((A.column IS NULL) <> (B.column IS NULL)))
,假设“Table.column IS NULL”是布尔值,并且我可以比较 2 个布尔值。但...
“<”附近的语法不正确。
我不喜欢
((A.column <> B.column) OR ((A.column IS NULL) AND (B.column IS NOT NULL)) OR
((A.column IS NOT NULL) AND (B.column IS NULL)))
我该如何解决这个问题?
问候,
I have a subquery, used in WHERE section:
A.column <> B.column
Unfortunately, it doesn't work, if either A.column or B.column is NULL. So, I converted it to:
((A.column <> B.column) OR ((A.column IS NULL) <> (B.column IS NULL)))
, presuming that "Table.column IS NULL" is boolean value and I can compare 2 boolean values. But...
Incorrect syntax near '<'.
I don't like
((A.column <> B.column) OR ((A.column IS NULL) AND (B.column IS NOT NULL)) OR
((A.column IS NOT NULL) AND (B.column IS NULL)))
How could I workarounf this?
Regards,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当两个值相等时 NULLIF 产生 null =)
NULLIF yields null when two values are equal =)
使用 ISNULL 函数。
Use ISNULL function.
在 MySQL 中,您可以使用
WHERE A <> 执行操作B
也适用于 null。请参阅: http://dev.mysql.com /doc/refman/5.0/en/comparison-operators.html#operator_equal-to
In MySQL you can use
To do a
WHERE A <> B
that also works on null.See: http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_equal-to