好的,我有以下MySQL查询:
SELECT COUNT(*) FROM `dates` WHERE firstDate IS NOT NULL AND secondDate IS NOT NULL
AND DATEDIFF(secondDate, firstDate) >= 30
该查询返回值9.然后使用以下查询:
SELECT COUNT(*) FROM `dates` WHERE firstDate IS NOT NULL AND secondDate IS NOT NULL
AND DATEDIFF(secondDate, firstDate) >= 90
第二个查询返回结果12.这怎么可能?这两个日期都是MySQL数据库中的日期数据类型。
答案 0 :(得分:2)
尝试这样做
SELECT firstDate, secondDate, DATEDIFF(secondDate, firstDate) AS diff
FROM `dates` WHERE firstDate IS NOT NULL AND secondDate IS NOT NULL
AND DATEDIFF(secondDate, firstDate) >= 30
SELECT firstDate, secondDate, DATEDIFF(secondDate, firstDate) AS diff
FROM `dates` WHERE firstDate IS NOT NULL AND secondDate IS NOT NULL
AND DATEDIFF(secondDate, firstDate) >= 90
您将看到实际的行列表,而不是结果行的计数。 这可能会帮助你解决这个问题。