简体   繁体   中英

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.

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM