您的位置:首页 > 数据库 > Oracle

oracle 查询重复数据并且删除, 只保留一条数据的SQL语句

2017-10-28 21:04 821 查看
delete from t_account where feedate in (

  select feedate

          from t_account

  group by feedate

  having count(1)>1

) and id not in (

  select min(id)

          from t_account

  group by feedate

  having count(1)>1

)

------------------------------------------------

delete from (

  select * from t_account

  where id not in(select min(id) from t_account group by feedate)

) t;

--------------------------------------------------

delete from t_account

 where id in (select id

                from t_account

               where feedate in (select feedate

                                   from t_account

                                  group by feedate

                                 having count(*) > 1)

              minus

              select min(id)

                from t_account

               where feedate in (select feedate

                                   from t_account

                                  group by feedate

                                 having count(*) > 1)

               group by feedate)

---------------------------------------------------

delete from t_account where id in

(

  select id from

    (

    select rank() over(order by feedate) r ,ac.* from t_account ac

    minus

    select row_number() over(order by feedate) r, ac.* from t_account ac

    )

);

----------------------------------------------------

delete  from t_account top

where

to_char(top.feedate)in(

       select up1.up1date from

       (select to_char(feedate) up1date,count(id) up1num from t_account  group by(to_char(feedate)) ) up1

       where up1.up1num>1

)

and

top.id not in(

        select min(tac.id) up3id from (

             select up1.up1date up2date from

             (select to_char(feedate) up1date,count(id) up1num from t_account  group by(to_char(feedate)) ) up1

             where up1.up1num>1

       )up2 left join t_account tac on up2.up2date=to_char(tac.feedate) group by to_char(tac.feedate)  

)

-----------------------------------------------------------

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: