python - 如何在 python 中增加查询值?

标签 python mysql sql sql-update

self.mycursor = self.mydb.cursor()
self.sql1 = "UPDATE counter SET count = %s WHERE id = %s"
self.val1 = (str(int('count' + 1)), '1')
self.mycursor.execute(self.sql1, self.val1)
self.mydb.commit()

在这部分代码中,我想增加查询值

最佳答案

如果您希望给定 id 的计数器加 1,您可以这样做:

self.sql1 = "UPDATE counter SET count = count + 1 WHERE id = %s"
self.val1 = (1)
self.mycursor.execute(self.sql1, self.val1)

关于python - 如何在 python 中增加查询值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59896641/

相关文章:

python - 多维数组上的映射函数

c# - 使用 EF 和 Linq 通过另一个表字段值查找表中的字段

php - 使用 php,如何查询 MySQL 表中行中存储的某些关键字以显示相关信息?

python - 在 python 中查找命令失败,出现 "missing argument to -exec"

python - 如何在 Jupyter Notebook 中创建模块并导入它们? Python

python - 如何让 groupby() 组在条件下加倍?

php - 连接到数据库 Zend、MySQL、MAMP、Mac、OSX 时出错

mysql - TableAdapter 中查询的 IIF 语句错误

mysql - 错误代码 : 1066. 不是唯一的表/别名: 'circle_call_prefixes'

SQL Server : unique identifier list