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)
)
-----------------------------------------------------------
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)
)
-----------------------------------------------------------
相关文章推荐
- Oracle 删除重复数据只留一条 查询及删除重复记录的SQL语句 1、查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断 select * from 表 wher
- oracle 查询重复数据并且删除, 只保留一条数据
- oracle 查询重复数据并且删除, 只保留一条数据
- Oracle 删除重复数据只留一条 查询及删除重复记录的SQL语句 1、查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断 select * from 表 wher
- oracle 查询重复数据并且删除, 只保留一条数据
- 删除oracle 表中重复数据sql语句、保留rowid最小的一条记录
- oracle 查询重复数据并且删除, 只保留一条数据
- Oracle查询重复数据并删除,只保留一条记录
- SQL语句删除2条重复数据一条保留一条
- SQL删除重复数据只保留一条语句
- Oracle查询重复数据并删除,只保留一条记录
- SQL语句删除2条重复数据一条保留一条
- Oracle查询重复数据并删除,只保留一条记录
- Oracle查询重复数据并删除,只保留一条记录
- Oracle查询重复数据并删除,只保留一条记录
- 笔记:Oracle查询重复数据并删除,只保留一条记录
- 笔记:Oracle查询重复数据并删除,只保留一条记录
- Oracle查询重复数据并删除,只保留一条记录
- 关于mysql中删除重复记录,并保留重复数据中的一条数据的SQL语句理解
- SQL语句删除2条重复数据一条保留一条