分享按钮

mysql 数据去重

默认分类 / 9613人浏览 / 0人评论

删除重复数据


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

);


感谢博主,喝杯咖啡~

请喝咖啡


感谢博主,喝杯咖啡~

心灵鸡汤

如果爱他,接受他的现在,别幻想他的改变。如果他能改,当然最好,不然,就想一想,你能不能接受。婚前的每一个缺点,婚后都会被放大。他抽烟,而你又爱他,就努力接受吧,婚后戒烟的男人太少了。其他缺点也是一样。