我的 SQL 中有两个表。 表1数据较多,表2数据量较大。
这是我使用 Python 实现的代码
import MySQLdb
db = MySQLdb.connect(host = "localhost", user = "root", passwd="", db="fak")
cursor = db.cursor()
#Execute SQL Statement:
cursor.execute("SELECT invention_title FROM auip_wipo_sample WHERE invention_title IN (SELECT invention_title FROM us_pat_2005_to_2012)")
#Get the result set as a tuple:
result = cursor.fetchall()
#Iterate through results and print:
for record in result:
print record
print "Finish."
#Finish dealing with the database and close it
db.commit()
db.close()
但是,这需要很长时间。我已经运行了 Python 脚本 1 小时,但它仍然没有给我任何结果。
请帮助我。
最佳答案
两个表中都有 Invention_title 索引吗?如果没有,则创建它:
ALTER TABLE auip_wipo_sample ADD KEY (`invention_title`);
ALTER TABLE us_pat_2005_to_2012 ADD KEY (`invention_title`);
然后将您的查询合并为一个不使用子查询的查询:
SELECT invention_title FROM auip_wipo_sample
INNER JOIN us_pat_2005_to_2012 ON auip_wipo_sample.invention_title = us_pat_2005_to_2012.invention_title
让我知道你的结果。
关于python - MySQL - 匹配两个包含巨大数据的表并找到相似的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16632582/