除了前两个选定日期,我需要删除数据库中的所有日期:
SELECT DateColumn
FROM Table
GROUP BY date(DateColumn)
ORDER BY DateColumn DESC
我希望在一个查询中删除除前两个之外的所有日期。
答案 0 :(得分:4)
delete from table where DateColumn not in(
SELECT DateColumn
FROM Table
GROUP BY date(DateColumn)
ORDER BY DateColumn DESC LIMIT 2)
答案 1 :(得分:3)
DELETE FROM Table
WHERE DateColumn NOT IN (SELECT DateColumn
FROM Table
GROUP BY date(DateColumn)
ORDER BY DateColumn DESC
LIMIT 2);