删除重复数据
delete from fa_user_view_copy1 where id in(
#为了解决You can‘t specify target table ‘test‘ for update in FROM clause错误
select id from (
#找出所有符合删除条件的id
select id from fa_user_view_copy1 where
#条件一
(user_id,pid,createtime,question_id) in (
#数据相同的字段的值
select user_id,pid,createtime,question_id from fa_user_view_copy1 group by user_id,pid,createtime,question_id having count(*) > 1
)
and
#条件二
id not in (
#数据相同的最小id
select min(id) from fa_user_view_copy1 group by user_id,pid,createtime,question_id having count(*) > 1
)
and finish_time = 0
) as a
);
delete from fa_user_view where id in(
#为了解决You can‘t specify target table ‘test‘ for update in FROM clause错误
select id from (
#找出所有符合删除条件的id
select id from fa_user_view where
#条件一
(user_id,pid,createtime) in (
#数据相同的字段的值
select user_id,pid,createtime from fa_user_view group by user_id,pid,createtime having count(*) > 1
)
and
#条件二
id not in (
#数据相同的最小id
select min(id) from fa_user_view group by user_id,pid,createtime having count(*) > 1
)
and finish_time = 0
) as a
);
感谢博主,喝杯咖啡~
感谢博主,喝杯咖啡~