4

我正在寻找一种简单的方法来选择日期时间列 000-00-00 00:00:00 (基本上是默认的未设置值)。

以下查询似乎有效:

SELECT * FROM myTable WHERE datetimeCol < 1

但这会一直可靠地工作并跨越不同的 mysql 版本吗?

4

4 回答 4

8

I would check for "zero" dates like this:

SELECT * FROM myTable WHERE datetimeCol = CONVERT(0,DATETIME)

I would prefer the equality predicate over an inequality predicate; it seems to convey my intentions more clearly. And if there are more predicates in the statement, and if the datetimeCol is a leading column in an index, it may help the optimizer make use of a multi-column index.

于 2013-01-23T22:26:27.903 回答
4

尝试这个:

SELECT * FROM myTable WHERE datetimeCol = '0000-00-00 00:00:00'

事后看来可能很明显;)

于 2013-01-23T21:31:10.020 回答
3

如何与0价值进行比较:

datetimeCol = 0
于 2013-01-23T21:37:47.570 回答
3

尝试这个:

SELECT * FROM myTable WHERE UNIX_TIMESTAMP(datetimeCol) = 0

于 2015-01-15T04:06:21.137 回答