谁能告诉我为什么它不返回任何结果?我正在尝试将数据从JSON
列复制到新列中,将那些结果乘以10%,然后在增加10%的人口旁边显示原始人口。
Python似乎可以运行此命令,但不会返回任何结果。
try:
query = ("UPDATE city SET Population = info->'$.Population' WHERE info->'$.Population' > 0")
cursor.execute(query)
conn.commit()
except Exception as ex:
print("cursor execution failure: " + str(ex))
query = ("SET Population = Population * 1.1")
cursor.execute(query)
conn.commit()
except Exception as ex:
print("cursor execution failure: " + str(ex))
query = ("SELECT Name, info->’$.Population’, Population FROM city;")
cursor.execute(query)
except Exception as ex:
print("cursor execution failure: " + str(ex))
for row in cursor:
print(u"{:<45} {:<45}".format(*row))
最佳答案
SET的SQL语法为false,必须替换:
query = ("SET Population = Population * 1.1")
通过
query = ("UPDATE city SET Population = Population * 1.1")
关于python - Python不返回任何MySQL结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50539758/