尝试获取匹配TableA和TableB的筛选结果,其中列col1和WHERE都是python变量“Bingo”not in TableB col3
bingo = 'Data1'
SQL = 'SELECT a.* FROM TABLEA a WHERE a.col1 NOT IN (SELECT col1 FROM TABLEB) AND (?) NOT IN (SELECT col3 FROM TABLEB);'
rows = cur.execute(SQL,bingo).fetchall()
答案 0 :(得分:2)
您无法参数化该字段的名称。最好使用Python str.format()替换/格式化,例如:
bingo = 'Data1'
SQL = 'SELECT a.* FROM TABLEA a WHERE a.col1 NOT IN (SELECT col1 FROM TABLEB) AND {} NOT IN (SELECT col3 FROM TABLEB);'.format(bingo)
rows = cur.execute(SQL).fetchall()