SELECT * FROM table WHERE datefield IS NULL
返回20条记录
SELECT * FROM table WHERE datefield IS NOT NULL
返回相同的 20 条记录以及输入日期的另外 20 条记录
IS NULL
和 IS NOT NULL
不是互斥的吗?
字段定义为:
日期字段日期不为空
最佳答案
没有显式默认值的 NOT NULL
列将使用隐式默认值(针对该类型)。对于日期
列,默认值为0
。
来自 MySQL docs :
If the column cannot take NULL as the value, MySQL defines the column with an explicit DEFAULT clause, using the implicit default value for the column data type. Implicit defaults are defined as follows:
- For date and time types other than TIMESTAMP, the default is the appropriate “zero” value for the type. For the first TIMESTAMP column in a table, the default value is the current date and time. See Section 11.3, “Date and Time Types”.
关于mysql IS NULL 和 IS NOT NULL 不互斥,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24289213/