宁波网站建设优化诊断,兰州一氧化碳,无锡抖音代运营公司,中国优秀网站设计去除重复数据#xff1a;
group by 对要比对的字段进行查询是否重复
CREATE TABLE 临时表 AS
(select 字段1,字段2,count(*) from 表名 group by 字段1,字段2 having count(*) 1)
上面这句话就是建立了临时表#xff0c;并将查询到的数据插入其中。
下面就可以进行…去除重复数据
group by 对要比对的字段进行查询是否重复
CREATE TABLE 临时表 AS
(select 字段1,字段2,count(*) from 表名 group by 字段1,字段2 having count(*) 1)
上面这句话就是建立了临时表并将查询到的数据插入其中。
下面就可以进行这样的删除操作了
delete from 表名 a where 字段1,字段2 in (select 字段1字段2 from 临时表);
使用rowid 会保存最新的一条记录
delete from 表名 a
where a.rowid !
(
select max(b.rowid) from 表名 b
where a.字段1 b.字段1 and
a.字段2 b.字段2
)
---效率好点的要使用临时表
create table 临时表 as
select a.字段1,a.字段2,MAX(a.ROWID) dataid from 正式表 a GROUP BY a.字段1,a.字段2;
delete from 表名 a
where a.rowid !
(
select b.dataid from 临时表 b
where a.字段1 b.字段1 and
a.字段2 b.字段2
);
commit;
完全删除重复的数据
CREATE TABLE 临时表 AS (select distinct * from 表名);
drop table 正式表;
insert into 正式表 (select * from 临时表);
drop table 临时表;