python在没有for循环的sql语句中列出list的值

2024-05-17 10:18:56 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的数据:

mylist=["happy" , "sad", "cute"]
country = 'US'

我的桌子

^{pr2}$

在python中,我的sql查询如下所示:

    myquery= 
"""select * from mytable where country = '%s' and terms is in ('%s', '%s');""" %(country, tuple(mylist)) 

错误:格式字符串的参数不足。在


Tags: 数据fromcutesqlmytablewhereselectcountry