【发布时间】:2020-01-09 13:32:33
【问题描述】:
我有以下脚本:
now = dt.datetime.now()
date_filter = now - timedelta(days=3)
list_ids = [1,2,3]
dq_connection = mysql.connector.connect(user='user', password='pass', host='localhost', database='db')
engine = create_engine('localhost/db')
cursor = connection.cursor(buffered=True)
query = ('''
SELECT *
FROM (SELECT * FROM myTable1 WHERE id in {%s}
WHERE date >= %s;
''')
df = pd.read_sql_query(query, connection,params=(list_ids,date_filter,))
我想在我的查询中有两个过滤器: 1) 列出我在 list_ids 上的所有 ID 2) 只过滤 date_filter 之前的日期。
第二个过滤器我可以做到,但是当我尝试使用得到的列表时:
pandas.io.sql.DatabaseError: Execution failed on sql
我做错了什么?
【问题讨论】: