使用python编写的SQL查询不断出现错误。
这是有问题的代码:
else:
else_query = "SELECT count(*) FROM PARKING_SPOTS WHERE OCCUPANCY = %s"
cursor.execute(else_query, (occupancy,)
" AND WHERE LOCATION = %s", (location,))
这是错误消息:
File "exp1", line 116
" AND WHERE LOCATION = %s", (location,))
^
SyntaxError: invalid syntax
谁能发现错误?我已经进行了数次更改,包括将SQL查询的一部分包含在一个变量中,但是我收到了同样的错误。
答案 0 :(得分:2)
所以做到:
else_query = """SELECT count(*) FROM PARKING_SPOTS WHERE OCCUPANCY = %s
AND LOCATION = %s
"""
cursor.execute(else_query, (occupancy, location))
查询参数需要作为元组传递