概述
我正在尝试用MySQL建立一个足球数据库。我做了一个选择,其中包含团队,我想在另一个选择中循环它们,所以我没有写18个不同的选择。你能帮帮我吗,我哪里出错了?我总是犯错误。k = 0
#Teams in one list
my_sq7 = "SELECT Team FROM bundesligatabella_2020_2021"
my_cursor.execute(my_sq7)
result3 = my_cursor.fetchall()
for row in result3:
my_sq9 = "SELECT SUM(Home_scored) FROM bundesliga_2020_2021_2 WHERE Home = %s"
my_cursor.executemany(my_sq9, result3[k][0])
result4 = my_cursor.fetchall()
k += 1
我还想把结果保存在另一个列表中,以更新另一列。
错误:Traceback (most recent call last):
File "pythondatabase.py", line 141, in
my_cursor.executemany(my_sq9, result3[k][0])
File "PythonPython39libsite-packagesmysqlconnectorcursor.py", line 675, in executemany
self.execute(operation, params)
File "PythonPython39libsite-packagesmysqlconnectorcursor.py", line 569, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "PythonPython39libsite-packagesmysqlconnectorconnection.py", line 651, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "PythonPython39libsite-packagesmysqlconnectorconnection.py", line 538, in _handle_result
raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1
最后
以上就是饱满唇膏为你收集整理的python mysql while循环_PythonMySQL我如何循环通过一个选择?的全部内容,希望文章能够帮你解决python mysql while循环_PythonMySQL我如何循环通过一个选择?所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复