[英]How to filter the datetime column in a SQL table with SQLalchemy in python?
I have a SQL table, and I query the table with SQLalchemy with python.我有一个 SQL 表,我使用 SQLalchemy 和 python 查询该表。
goog = pd.read_sql("\
\
SELECT dp.price_date, dp.adj_close_price \
FROM symbol AS sym \
INNER JOIN daily_price AS dp \
ON dp.symbol_id = sym.id \
WHERE sym.ticker = 'GOOG' \
ORDER BY dp.price_date ASC",
con = engine,
index_col='price_date')
Now my problem is, the price_date data type is datetime, I tried to filter in the WHERE clause, but failed.现在我的问题是,price_date 数据类型是 datetime,我试图在 WHERE 子句中进行过滤,但失败了。 Like this:像这样:
price_date BETWEEN 2021-11-08 00:00:00.00000 AND 2021-11-12 00:00:00.000000
and this:和这个:
price_date BETWEEN 2021-11-08 AND 2021-11-12
Any solution?有什么解决办法吗?
in both cases dates need a single quote在这两种情况下,日期都需要单引号
price_date BETWEEN '2021-11-08 00:00:00.00000' AND '2021-11-12 00:00:00.000000'
and this:和这个:
DATE(price_date) BETWEEN '2021-11-08' AND '2021-11-12'
Also good for reading about quotes in mysql When to use single quotes, double quotes, and backticks in MySQL也适合阅读 mysql 中的引号何时在 MySQL 中使用单引号、双引号和反引号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.