我有两个表,sales_olap
和resellers
我需要打印sales_olap
表中<{1}}中不存在来自resellers
的转销商
例如:
result = cursor.execute("SELECT SO.reseller_name FROM sales_olap AS SO WHERE
SO.reseller_name!=(SELECT reseller FROM resellers)")
for row in result:
print row
但我收到的错误是:1242, Subquery returns more than 1 row
我怎样才能让它只打印sales_olap
表中resellers
表中不存在的经销商名称?
如果我尝试:
result = cursor.execute("SELECT reseller_name FROM sales_olap WHERE reseller_name NOT IN(SELECT reseller FROM resellers)")
for row in result:
print row['reseller_name']
然后我收到错误:TypeError: 'long' object is not iterable
答案 0 :(得分:0)
能够通过这种方式实现这一目标:
cursor.execute("SELECT reseller_name FROM sales_olap LEFT JOIN resellers ON sales_olap.reseller_name=resellers.reseller WHERE resellers.reseller IS NULL")
result = cursor.fetchall()
for row, in result:
print (row)