Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嗨,我需要从 a 列中选择所有内容,但如果值为 1,则 b 列中的值不能为 NULL。你如何在 WHERE 子句中写这个?
你可以这样写:
where a <> 1 or b is not null
或等效地:
where not (a = 1 and b is null)
注意:这些假设a不为空。为了解决这个问题,您可以显式测试它:
a
where a <> 1 or a is null or b is not null
你可以把它写成:
其中(a = 1 AND b 不为空)