Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.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 根据两列中的值更新mysql数据库_Python_Mysql_Mysql Python - Fatal编程技术网

Python 根据两列中的值更新mysql数据库

Python 根据两列中的值更新mysql数据库,python,mysql,mysql-python,Python,Mysql,Mysql Python,我有一个MySQL数据库,有4列:X\u-coord,Y\u-coord,num\u-pos,num\u-neg 我要做的是更新与特定位置对应的num_pos,该位置存储在名为location的数组中,其中location[0]是X_坐标,而location[1]是Y_坐标,我希望这样动态执行: sql = "UPDATE sentimentdata SET num_pos = num_pos + 1 WHERE X_coord = '%s' and Y_coord = '%s'" %

我有一个MySQL数据库,有4列:
X\u-coord
Y\u-coord
num\u-pos
num\u-neg

我要做的是更新与特定位置对应的num_pos,该位置存储在名为location的数组中,其中
location[0]
X_坐标
,而
location[1]
Y_坐标
,我希望这样动态执行:

sql = "UPDATE sentimentdata SET num_pos = num_pos + 1 WHERE X_coord = '%s' and Y_coord = '%s'"    %    (location[0],location[1])

我的问题是这个
%s
格式行吗?

行,应该行……你没试过吗? 或者你可以这样写

sql = """UPDATE sentimentdata SET num_pos=num_pos+1 WHERE X_coord=%s and Y_coord=%s"""
cursor.execute(sql,(location[0],location[1]))
如果位置[0]=x且位置[1]=y,则等于:

cursor.execute("""UPDATE sentimentdata SET num_pos=num_pos+1 WHERE X_coord=x and Y_coord=y""")

我应该提到,我在mysqldb中使用python