我在两个不同的表中有两列。
列PCTNo
具有以下值:US2002014866
列pct_publishing_data
具有以下值:JP1014866
我想得到PCTNo
的最后5个值和pct_publishing_data
的最后5个值,如果pct_publishing_data
的5个数字在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()
但它不起作用,它给了我全部
救命啊。你知道吗
它应该可以正常工作,您可以使用
AND
,因为您只想在右端和左端匹配时显示它们。但当然US2002014866
与JP1014866
不匹配,因为匹配它应该是US1014866
。你知道吗这里有一个SQL Fiddle可以做到这一点(我简化了表和列名)
结果只有一行:
相关问题 更多 >
编程相关推荐