使用MYSQL导入文本并导出的方式过滤重复数据

时间:14-11-10 栏目:问题及解决 作者:admin 评论:0 点击: 2,191 次

old.txt内容如下:

a1dsbabe
a8X5g
a8X5g
aaaaaaaaha
AarleOostFront
Aaronski09
AB51194
AbDaveilliers
AB51194

MYSQL命令如下:

USE test;
DROP TABLE IF EXISTS test;
CREATE TABLE test (name CHAR(200)) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
LOAD DATA INFILE 'D:/old.txt' INTO TABLE test;
SELECT COUNT(name) AS 所有,COUNT(DISTINCT name) AS 去重 FROM test;
SELECT DISTINCT name FROM test INTO OUTFILE "d:/new.txt";

new.txt结果如下

a1dsbabe
a8X5g
aaaaaaaaha
AarleOostFront
Aaronski09
AB51194
AbDaveilliers

将所有olda.txt文档中不含oldb.txt中的数据导出来为newd.txt

#将所有olda.txt文档中不含oldb.txt中的数据导出来为newd.txt
USE test;
DROP TABLE IF EXISTS testa;
CREATE TABLE testa (name CHAR(20)) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
LOAD DATA INFILE 'D:/olda.txt' INTO TABLE testa;
DROP TABLE IF EXISTS testb;
CREATE TABLE testb (name CHAR(20)) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
LOAD DATA INFILE 'D:/oldb.txt' INTO TABLE testb;

SELECT COUNT(name) AS 所有,COUNT(DISTINCT name) AS 去重 FROM testa;
SELECT COUNT(name) AS 所有,COUNT(DISTINCT name) AS 去重 FROM testb;
SELECT  COUNT(DISTINCT name) 过滤 FROM `testa` where name not in(select name from testb);

SELECT  DISTINCT name FROM `testa` where name not in(select name from testb) INTO OUTFILE "d:/newd.txt";


声明: 本文由( admin )原创编译,转载请保留链接: 使用MYSQL导入文本并导出的方式过滤重复数据

使用MYSQL导入文本并导出的方式过滤重复数据:等您坐沙发呢!

发表评论


------====== 本站公告 ======------
联系信息:
lxq73061#qq.com qq:583964941
支付宝:https://me.alipay.com/lxq73061
相关插件程序等信息均会在站内发布,敬请关注。

读者排行