sql insert into两次怎么删除重复数据
答案:5 悬赏:10
解决时间 2021-02-18 15:14
- 提问者网友:刪除丶後
- 2021-02-17 20:37
我在pl/sql里 用insert into语句把同样的数据插入了2次 请问怎么才能删除重复的数据
最佳答案
- 二级知识专家网友:木子香沫兮
- 2021-02-17 22:15
有关键字吗?如ID,没有的话加一个ID字段进去,自增加的。
delete 表
where id in
(
select min(id) from 表
group by 字段1+字段2+...
---用来判断重复数据
)
delete 表
where id in
(
select min(id) from 表
group by 字段1+字段2+...
---用来判断重复数据
)
全部回答
- 1楼网友:时光不老我们不分离
- 2021-02-18 02:09
假如 table 名称为test
1. create table temp as select distinct * from test;
2. 你可以删除test,将表temp 重命名为test---rename temp to
test;当然你也可以进行一下操作
3. truncate table test; --清空表test;
4. insert into test select * from temp;
5. drop table temp;
如果对于有历史数据的表来讲,可以在1步骤中加入where条件,在3表中不进行truncate清空表操作,改为删除限定数据操作。
谢谢~~
- 2楼网友:蜜罐小熊
- 2021-02-18 01:35
全部删除 重新插入数据
- 3楼网友:滚出爷的世界
- 2021-02-18 00:03
假如 table 名称为test
1. create table temp as select distinct * from test;
2. 你可以删除test,将表temp 重命名为test---rename temp to
test;当然你也可以进行一下操作
3. truncate table test; --清空表test;
4. insert into test select * from temp;
5. drop table temp;
如果对于有历史数据的表来讲,可以在1步骤中加入where条件,在3表中不进行truncate清空表操作,改为删除限定数据操作。
谢谢~~
- 4楼网友:偏爱自由
- 2021-02-17 22:40
比如有三个字段
表名假如test
id name price
1 张三 10
1 张三 10
2 李四 20
2 李四 20
delete from test where rowid in (select min(rowid) from test group by id,name,price) ;
你照着改一下吧
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯