0

嗨,我需要从 a 列中选择所有内容,但如果值为 1,则 b 列中的值不能为 NULL。你如何在 WHERE 子句中写这个?

4

2 回答 2

1

你可以这样写:

where a <> 1 or b is not null

或等效地:

where not (a = 1 and b is null)

注意:这些假设a不为空。为了解决这个问题,您可以显式测试它:

where a <> 1 or a is null or b is not null
于 2021-04-21T12:16:42.077 回答
0

你可以把它写成:

其中(a = 1 AND b 不为空)

于 2021-04-21T13:00:37.057 回答