尝试删除某些条件但MySQL抛出错误的记录:
Error Code: 1093
delete from tbl1
where date(cast(traptime as datetime))< date_sub(current_date, interval 200 day) and
id not in (select max(id) as id from tbl1 group by device_name);
答案 0 :(得分:1)
试试这个:
DELETE FROM tbl1
WHERE id NOT IN (
SELECT id FROM (
select max(id) as id from tbl1 group by device_name
) AS c
)
and date(cast(traptime as datetime))< date_sub(current_date, interval 200 day)
答案 1 :(得分:0)
在MySQL中,您无法修改在SELECT部分中使用的同一个表。在这里看到答案: MySQL Error 1093 - Can't specify target table for update in FROM clause