Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.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 - Fatal编程技术网

Python/MySQL在同一查询中选择、更新和获取

Python/MySQL在同一查询中选择、更新和获取,python,mysql,Python,Mysql,我想在一个查询中选择和更新 在我的数据库中,我有需要检查的category\u ids。我想通过DESC选择上次更新的查询,并使用runs=runs+1对其进行更新,这样它就可以对其进行计数,并自动更新last\u update字段 但是由于某种原因,我拿不到它 cursor.execute( "UPDATE categorys as t1, (SELECT category_id FROM categorys ORDER BY last_update LIMIT 1)

我想在一个查询中选择
更新

在我的数据库中,我有需要检查的
category\u id
s。我想通过
DESC
选择上次更新的查询,并使用
runs=runs+1
对其进行更新,这样它就可以对其进行计数,并自动更新
last\u update
字段

但是由于某种原因,我拿不到它

cursor.execute(
"UPDATE categorys as t1, 
(SELECT category_id 
 FROM categorys 
 ORDER BY last_update 
 LIMIT 1) as t2 
 SET t1.runs = t1.runs+1 
 WHERE t2.category_id = t1.category_id")
row = cursor.fetchone()
print(row)
print(row)
为我提供了
None
但我需要
类别id


更新工作并统计上次更新的
运行+1
DESC
mysql更新不会返回已更改数据的值。它只返回运行正常的查询

您需要执行select语句来返回category\u id