【发布时间】:2019-05-12 18:37:07
【问题描述】:
我正在尝试从我的数据库中的表中获取速度值列表。我想知道它们是否是允许我在 WHERE 函数中传递 CharID 列表的 SQL 命令/方法,这样我就不必创建 FOR 循环并分别执行四个搜索。
party_ids= [4, 3, 1, 2]
def initializegame(party_ids):
#Get selected party members IDS
print(party_ids)
#Obtain Speeds
fetchspeed=("SELECT startspeed FROM characters WHERE CharID=%s")
print(fetchspeed)
mycursor.execute(fetchspeed,party_ids)
myspeeds=mycursor.fetchall()
print(myspeeds)
print("done")
我对 SQL 比较陌生,可能会漏掉一些重要的东西。
我确实尝试过: passing a list to a where clause 然而,这有点难以理解。
提前致谢
【问题讨论】: