Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在sql查询中使用整型变量_Python_Mysql_Python 3.x_Sqlite - Fatal编程技术网

Python 如何在sql查询中使用整型变量

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语句

使用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语句中使用占位符,然后传入包含要查找的特定值的元组:

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)

你在找字符串插值吗?