Python 使用WHERE和“'”进行查询时,jupyter笔记本中的查询出错
我试图在jupyter笔记本中进行查询,并将其保存在pandas数据框中 以下是我编写的代码:Python 使用WHERE和“'”进行查询时,jupyter笔记本中的查询出错,python,sql-server,pandas,dataframe,jupyter-notebook,Python,Sql Server,Pandas,Dataframe,Jupyter Notebook,我试图在jupyter笔记本中进行查询,并将其保存在pandas数据框中 以下是我编写的代码: import pyodbc conn = pyodbc.connect('Driver={SQL Server};' 'Server=DESKTOP-P2RVLB2\RENO_DATACAMP;' 'Database=Introduction_to_SQL_Server;'
import pyodbc
conn = pyodbc.connect('Driver={SQL Server};'
'Server=DESKTOP-P2RVLB2\RENO_DATACAMP;'
'Database=Introduction_to_SQL_Server;'
'Trusted_Connection=yes;')
cursor = conn.cursor()
# SELECT the country column FROM the eurovision table
sql_query = pd.read_sql_query('SELECT description, event_year from Introduction_to_SQL_Server.dbo.grid WHERE description ='Vandalism';',conn)
print(sql_query)
print(type(sql_query))
其错误如下所示:
File "<ipython-input-69-0c8fd6cbc2be>", line 9
sql_query = pd.read_sql_query('SELECT description, event_year from Introduction_to_SQL_Server.dbo.grid WHERE description ='Vandalism';',conn)
^
SyntaxError: invalid syntax
请帮我解决这个错误,提前谢谢 对整个查询使用双引号,对查询内部使用单引号
sql_query = pd.read_sql_query("SELECT description, event_year from Introduction_to_SQL_Server.dbo.grid WHERE description ='Vandalism'",conn)
此外,我相信分号在查询结束时是不必要的嘿,它的工作!谢谢mitch,我刚刚学习了sql和python,我刚刚开始了解如何使用双引号和单引号。是的,分号是不需要的