返回100个特定姓氏的记录

返回100个特定姓氏的记录,第1张

返回100个特定姓氏记录

问题返回所有记录中包含的姓氏

tuple

核心是创建一个查询,该查询具有与

?
序列中一样多的绑定。
[:-1]
需要排除最后一个逗号
...?,

  • SQLite理解的SQL-子句
    surnames = ("Smith", "Murphy", "Owens")

    bindings = ‘?,’*len(surnames)
    QUERY = “select firstname, surname from census_data where surname in ({});”
    .format(bindings[:-1])
    print(QUERY)

    >>> select firstname, surname from census_data where surname in (?,?,?);

    cur.execute (QUERY, surnames)

使用Python:3.5.3-sqlite3:2.6.0测试



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5649558.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存