pandas.read_sql_query-如果列名和搜索值都包含空格,如何正确编写WHERE条件

问题描述 投票:0回答:1

我这样编写SQL查询

df = pd.read_sql_query('SELECT * FROM hr_dataset WHERE "Performance Score" = "Needs Improvement";', conn)
hr_dataset - table
Performance Score - column
Needs Improvement - searched value

列名和搜索值都包含一个空格,这就是为什么我必须使用引号,但是此查询结果出错。我应该如何正确编写这样的查询?

python sql pandas psycopg2
1个回答
0
投票

如果是SQL Server

SELECT * FROM hr_dataset WHERE [Performance Score] like '%Needs Improvement%'

如果是MySQL

SELECT * FROM hr_dataset WHERE `Performance Score` like '%Needs Improvement%'
© www.soinside.com 2019 - 2024. All rights reserved.