簡體   English   中英

當列表的類型為date NOT timestamp時,MySQL檢索過去24小時的數據

[英]MySQL retrieve data for the past 24 hours when the column table is of type date NOT timestamp

我正在嘗試檢索過去24小時的數據,但是什么也沒得到,但是當我直接在db中檢查表列(天)時,便可以找到它們。 這是我的查詢:

select * from mytable
where
days between concat(date(date_sub(now(), interval 1 day))

between需要2個參數來指定范圍:

select * from mytable
where days between date_sub(now(), interval 1 day) and now();

或者簡單地

select * from mytable
where days > date_sub(now(), interval 1 day);

您可以使用

select * from mytable where days > date_sub(CURDATE(),INTERVAL 1 DAY);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM