mysql IS NULL 和 IS NOT NULL 不互斥

标签 mysql null

SELECT * FROM table WHERE datefield IS NULL

返回20条记录

SELECT * FROM table WHERE datefield IS NOT NULL

返回相同的 20 条记录以及输入日期的另外 20 条记录

IS NULLIS 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/

相关文章:

php - 我的 PHP 页面未从 MySQL 数据库检索任何内容

javascript - 具有多个系列的 Highcharts 异步服务器加载

mysql - 从一张表复制到另一张表

date - 如何将带有时间(日期)类型的文件加载到 Hive 表中?

JAVA类空值

tsql - 是否有不同类型的 NULL?

php - MYSQL查询错误(结果数组)

MYSQL 计算返回错误值

c - (char*) 0 是什么意思?

c# - 如果对象不为空,则将对象添加到列表的简写