
mysql怎么在一个表里面添加数据
2个回答
展开全部
1、先添加完,删除所有重复的记录,再insert一次
insert into A select * from B;
insert into A select * from C;
insert into A select * from D;
2、删除重复的记录只保留一行
delete from A where name in (select id from t1 group by id having count(id) > 1)and rowid not in (select min(rowid) from t1 group by id having
count(*)>1);
3、记录一下这些重复的记录,
mysql -uroot -p123456 -Ddb01 -e 'select b.id from t1 b group by id having count(b.id) > 1' | tail -n +2 > repeat.txt
删除全部重复的记录
delete from A where name in (select name from t1 group by name having count(name) > 1;);
再次插入多删的重复记录
#!/bin/sh
for id1 in `cat repeat.txt`;do
mysql -uroot -p123456 -Ddb01 -e "insert into A select * from B where id='${id1}'"
done
insert into A select * from B;
insert into A select * from C;
insert into A select * from D;
2、删除重复的记录只保留一行
delete from A where name in (select id from t1 group by id having count(id) > 1)and rowid not in (select min(rowid) from t1 group by id having
count(*)>1);
3、记录一下这些重复的记录,
mysql -uroot -p123456 -Ddb01 -e 'select b.id from t1 b group by id having count(b.id) > 1' | tail -n +2 > repeat.txt
删除全部重复的记录
delete from A where name in (select name from t1 group by name having count(name) > 1;);
再次插入多删的重复记录
#!/bin/sh
for id1 in `cat repeat.txt`;do
mysql -uroot -p123456 -Ddb01 -e "insert into A select * from B where id='${id1}'"
done
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |