我正在使用MySQL连接器以便从Python查询MySQL数据库。
我有以下Python列表:
l = [a, b, c]
我想在以下查询中使用它:
cursor.execute ("SELECT id \
FROM table \
WHERE ratio = (SELECT MAX(ratio) \
FROM table \
WHERE name <> %s", (l,)))
如何在查询中插入此列表?
[就像@roganjosh提到的那样,您想使用cursor.executemany()
,https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-executemany.html中的更多详细信息