好的,我有以下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数据库中的日期数据类型。

最佳答案

试着做这个

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

您将看到实际的行列表,而不是结果行的计数。
那也许能帮你弄清楚这件事。

10-06 01:30