用下面的语句就报语法出错:
delete from tab_record where recordid not in
(select min(c.recordid) as recordid from tab_record c group by (c.dev_Id+c.StartTime+c.EndTime+c.CardNum));
报错如下:You can't specify target table '表名' for update in FROM clause
找到替代方案,改用下面的,OK:
delete from tab_record where recordid not in
(select min(c.recordid) as recordid from (select * from tab_record ) c group by (c.dev_Id+c.StartTime+c.EndTime+c.CardNum));
或者下面的也OK:
delete from tab_record where recordid not in
(select * from (
select min(recordid) as recordid from tab_record group by (dev_Id+StartTime+EndTime+CardNum)) v);