我正在寻找一种简单的方法来选择日期时间列 000-00-00 00:00:00 (基本上是默认的未设置值)。
以下查询似乎有效:
SELECT * FROM myTable WHERE datetimeCol < 1
但这会一直可靠地工作并跨越不同的 mysql 版本吗?
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.
尝试这个:
SELECT * FROM myTable WHERE datetimeCol = '0000-00-00 00:00:00'
事后看来可能很明显;)
如何与0
价值进行比较:
datetimeCol = 0
尝试这个:
SELECT * FROM myTable WHERE UNIX_TIMESTAMP(datetimeCol) = 0