我正在尝试执行以下查询:
people = ('mike', 'dave', 'andrew')
cursor.execute('SELECT * FROM peoples WHERE person IN %s', people)
但是,这会引发SQL异常。在mysql中使用IN *python tuple()*
的正确格式是什么?
答案 0 :(得分:3)
sql_stmt = 'SELECT * FROM peoples WHERE person IN (%s)' % ','.join(map(str,people))
cursor.execute(sql_stmt)