Python 如何在sql查询中使用整型变量
使用Python3,我使用以下查询搜索数据库,然而,num_tests是在python代码中计算的一个不断变化的整数值。其中:Python 如何在sql查询中使用整型变量,python,mysql,python-3.x,sqlite,Python,Mysql,Python 3.x,Sqlite,使用Python3,我使用以下查询搜索数据库,然而,num_tests是在python代码中计算的一个不断变化的整数值。其中: num_tests = randint(1, 100) 如何搜索num_tests的值而不将其更新到数据库中,我希望sql查询中的num_tests只取num_tests的预定值 test_db.execute('select count(testers) from test where' number_of_testers = num_tests') 在sql语句
num_tests = randint(1, 100)
如何搜索num_tests的值而不将其更新到数据库中,我希望sql查询中的num_tests只取num_tests的预定值
test_db.execute('select count(testers) from test where' number_of_testers = num_tests')
在sql语句中使用占位符,然后传入包含要查找的特定值的元组:
test_db.execute('select count(testers) from test where number_of_testers = ?', (num_tests,))
您可以使用以下选项:
test_db.execute('select count(testers) from test where number_of_testers = ?', num_tests)
你在找字符串插值吗?