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.
是否可以NULL在语句中包含类似的内容SELECT * FROM my_table WHERE my_field IN (1,2,NULL);?
NULL
SELECT * FROM my_table WHERE my_field IN (1,2,NULL);
如果不是,您如何建议只允许几个整数或 NULL?
最好使用OR这样的:
OR
SELECT * FROM my_table WHERE my_field IN (1,2) OR my_field IS NULL;
使用OR,它是你想要的最清晰的表达。
您还可以提供一个默认值以在何时my_field使用NULL
my_field
SELECT * FROM my_table WHERE COALESCE(my_field, 1) IN (1,2);
但是NULL在-list 中使用 a是IN行不通的,因为NULL通常不等于. (它也不是不相等的——它是未定义的)。NULL
IN