我有一个 Jupyter 笔记本,我想在其中执行查询。我正在使用 sqlalchemy,如果我在 PyCharm 中将其作为脚本运行,则以下代码工作正常:from sqlalchemy import create_engineimport pandas as pdengine = create_engine('mysql+mysqlconnector://user:password@server_address:3306/DBase', echo=False)connection = engine.connect()query = "SELECT week(date) as week, count(*) FROM table GROUP BY week"df = pd.read_sql(query, con=engine)print(df)但是,当我尝试在 Jupyter notebook 中运行它时,我会收到错误消息:ProgrammingError: (mysql.connector.errors.ProgrammingError) 1059 (42000): 标识符名称 'SELECT week(date) as week, count(*) FROM table GROUP BY week' 太长当我尝试类似的东西时query = "SELECT count(*) as number FROM table"它确实工作正常。一旦我向查询添加一些语句,它就会抛出错误。我不确定它为什么特别抱怨标识符。这似乎不是由于“AS”,因为如果我忽略它并添加 WHERE 语句,它也会抛出错误。有什么建议?
添加回答
举报
0/150
提交
取消