问题 :返回所有记录中包含的姓氏
tuple
核心是创建一个查询,该查询具有与
?序列中一样多的绑定。
在
[:-1]需要排除最后一个逗号
...?,。
- SQLite理解的SQL-子句
surnames = ("Smith", "Murphy", "Owens")
bindings = ‘?,’*len(surnames)
>>> select firstname, surname from census_data where surname in (?,?,?);
QUERY = “select firstname, surname from census_data where surname in ({});”
.format(bindings[:-1])
print(QUERY)cur.execute (QUERY, surnames)
使用Python:3.5.3-sqlite3:2.6.0测试
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)