【问题标题】:Finding values in the database在数据库中查找值
【发布时间】:2021-12-11 16:55:27
【问题描述】:

如何通过两个参数在数据库中查找值:

info = db.execute (
    f "SELECT * FROM 'storage_users' WHERE status =?, Type =?", [status, Type]
)

【问题讨论】:

    标签: python telegram-bot mysql-python


    【解决方案1】:

    我建议您使用某种 ORM,例如 peeweesqlalchemy 与程序中的数据库进行交互,因为它使与数据库的交互变得更加容易。

    为了回答您的问题,我认为您可以尝试以下方法:

    f "SELECT * FROM 'storage_users' WHERE status ='{status}', Type ='{Type}'"
    

    【讨论】:

      【解决方案2】:
      info = db.execute (
          f "SELECT * FROM 'storage_users' WHERE status = ? AND Type =?", [status, Type]
      )
      

      布尔运算符用于连接数据库查询中需要的两个条件。

      【讨论】:

      • 虽然此代码可能会回答问题,但提供有关 why 和/或 如何 此代码回答问题的附加上下文可提高其长期价值.
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-06
      • 2014-04-08
      • 2010-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多