繁体   English   中英

如何在python中增加查询值?

[英]How can I increment query value in python?

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)

您的问题不清楚,我假设您想增加给定 id 的计数值:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM