#删除重复的人员,并且最近时间不能是最近的
之前>>>
#进行删除
delete from tbluser where uid in (select uid from tbluser u where uid in (select u.uid from tbluser u
where uid in (
#筛选重复工号的人员
select uid from tbluser where accountID in (
#筛选重复的工号
select accountId from tbluser group by accountID having count(accountID) > 1
)
)
#去除uid最小的工号人员
and uid NOT in (
select uid from tbluser group by accountID having count(accountID) > 1
)));
报错如下>>>
1093 - You can’t specify target table ‘tbluser’ for update in FROM clause
解决方法:将select出的结果通过中间表再select一遍可以解决以上问题。
修改之后>>>
delete from tbluser where uid in (select a.uid from (select uid from tbluser u where uid in (
select uid from tbluser where accountID in (
select accountId from tbluser group by accountID having count(accountID) > 1
)
) and uid NOT in (
select uid from tbluser group by accountID having count(accountID) > 1
)) as a );
没报错解决问题