如何插入Python列表和MySQL查询?

问题描述 投票:0回答:1

我正在使用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,)))

如何在查询中插入此列表?

python mysql list mysql-python mysql-connector
1个回答
0
投票

[就像@roganjosh提到的那样,您想使用cursor.executemany()https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-executemany.html中的更多详细信息

© www.soinside.com 2019 - 2024. All rights reserved.