我想从mySql查询中排除否定结果。 这是我的查询:
SELECT
MAX(datediff(now(), date_ship)) AS days,
date_ship
FROM table
+------------+------+
| date_ship | days |
+------------+------+
| 2019-07-15 | -6 |
| 2019-07-12 | -3 |
| 2019-07-01 | 9 |
| 2019-06-25 | 14 |
+------------+------+
我只想得到负面结果:
+------------+------+
| date_ship | days |
+------------+------+
| 2019-07-15 | -6 |
| 2019-07-12 | -3 |
+------------+------+
答案 0 :(得分:0)
正如this comment中指出的那样,您的查询本质上应该是:
SELECT
MAX(datediff(now(), date_ship)) AS days,
date_ship
FROM table
GROUP BY date_ship
HAVING MAX(datediff(now(), date_ship)) < 0
;
答案 1 :(得分:0)
检查以下查询并尝试。
SELECT MAX(datediff(now(), date_ship)) AS days,
date_ship
FROM table WHERE MAX(datediff(now(), date_ship)) < 0;