由于数据库设计不合理(一张原表,一张更新记录表,偷懒直接复制的,忘了关联id),等发现的时候想写条SQL语句补救一下,结果报错了。
网上的例子
delete from tbl where id in
(
select max(id) from tbl a where EXISTS
(
select 1 from tbl b where a.tac=b.tac group by tac HAVING count(1)>1
)
group by tac
)
改:
delete from tbl where id in
(
select a.id from
(
select max(id) id from tbl a where EXISTS
(
select 1 from tbl b where a.tac=b.tac group by tac HAVING count(1)>1
)
group by tac
) a
)