超过 6 个月但不更新的客户

Rom*_*sch 0 mysql sql

我以这种方式请求过去 6 个月的客户:

SELECT customer
FROM table
WHERE date_of_last_order>date_sub(NOW(),INTERVAL 6 MONTH)
GROUP BY customer
ORDER BY customer ASC
Run Code Online (Sandbox Code Playgroud)

现在我还想要一份超过 6 个月的旧订单列表,但不应包括过去 6 个月的客户。

有任何想法吗?谢谢!

Gor*_*off 5

你想使用一个having子句:

SELECT customer
FROM table
GROUP BY customer
HAVING MAX(date_of_last_order) <= date_sub(NOW(), INTERVAL 6 MONTH)
ORDER BY customer ASC
Run Code Online (Sandbox Code Playgroud)