这是我的数据:
mylist=["happy" , "sad", "cute"]
country = 'US'
mytable的
id terms values
1 happy 3
2 sad 4
3 angry 5
在python中我的sql查询如下所示:
myquery=
"""select * from mytable where country = '%s' and terms is in ('%s', '%s');""" %(country, tuple(mylist))
错误的格式字符串参数不够。
答案 0 :(得分:0)
python的db adapter提供了参数格式化,你只需要使用它:
cursor.execute('select * from mytable where terms in %s and country = %s;', (tuple(mylist), country))