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

oracle删除重复数据并只保留一条数据

2014-02-24 11:40 323 查看
1.delete from t_test t1 where t1.id in (select t.id from t_test t group by t.id having count(1)>1)

and t1.rowid not in (select min(rowid) from t_test t group by t.id having count(*)>1)

补充:having和where区别

1.where:约束声明,在返回结果产生作用不支持聚合函数。

2.having:过滤声明,在返回结果后产生作用,从结果集中进行过滤,支持聚合函数。

3.聚合函数:sum、avg、min、max、count等函数

2.使用中间表

create table t_test1 as select distinct* from t_test;

truncate table t_test;

insert into t_test select * from t_test1;

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