我在两个不同的表中有两列。
列PCTNo
有这个值:US2002014866
列pct_publishing_data
有这个值:JP1014866
我想得到最后 5 个值PCTNo
和最后 5 个值,pct_publishing_data
如果 5 位pct_publishing_data
在PCTNo
和前 2 个值相同,那么它会显示出来。在这种情况下它不会出现
这是我一直在实现的代码。
import MySQLdb
db = MySQLdb.connect(host = "localhost", user = "root", passwd="", db="fak")
cursor = db.cursor()
#Execute SQL Statement:
cursor.execute("SELECT auip_wipo_sample.PCTNo FROM auip_wipo_sample INNER JOIN us_pat_2005_to_2012 ON RIGHT(auip_wipo_sample.PCTNo,5) = RIGHT(us_pat_2005_to_2012.pct_publishing_data,5) AND LEFT(auip_wipo_sample.PCTNo,2) = LEFT(us_pat_2005_to_2012.pct_publishing_data,2)")
#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()
但它不起作用,它给了我所有这些
帮助。