我有这个问题:
SELECT NAME, date, price
FROM purchase
WHERE Max(date) < '$lastweek'
AND NAME = '$customer'
GROUP BY NAME;
查询如何查找最近的日期并检查具有给定日期的日期?
答案 0 :(得分:1)
您可以尝试这样:
SELECT NAME, date, price
FROM purchase
WHERE (SELECT Max(date) FROM purchase) < '$lastweek'
AND NAME = '$customer'
GROUP BY NAME;
答案 1 :(得分:0)
您是否尝试将SELECT MAX(date)
作为子查询购买?
SELECT NAME, date, price
FROM purchase
WHERE (SELECT Max(date)) < $lastweek
答案 2 :(得分:0)
你可以这样做:
SELECT name, MAX(date) as latest_date, price
FROM purchase
WHERE name= '$customer'
GROUP BY name HAVING latest_date = '$date';