MySQL 查詢大於“時間字段”15分鍾、1小時、1天的數據


以下代碼中times為時間字段,類型為datetime

1.查詢大於times十五分鍾的數據

//大於號后面都是獲取times十五分鍾后的時間
select*from table where now() >SUBDATE(times,interval -15 minute);
select*from table where now() > SUBDATE(times,interval -900 second);
select*from table where now() > date_add(times,interval 15 minute);
select*from table where now() >ADDDATE(times,interval 15 minute);

2.查詢大於times一小時的數據

//大於號后面都是獲取times一小時后的時間
select*from table where now() >SUBDATE(times,interval -1 hour);
select*from table where now() > SUBDATE(times,interval -60*60 second);
select*from table where now() > date_add(times,interval -1 hour);
select*from table where now() >ADDDATE(times,interval 15 hour);

3.查詢大於times一天的數據

//大於號后面都是獲取times一天后的時間
select*from table where now() >SUBDATE(times,interval -1 day);
select*from table where now() > SUBDATE(times,interval -60*60*60 second);
select*from table where now() > date_add(times,interval -1 day);
select*from table where now() >ADDDATE(times,interval 15 day);

相應的如果想查詢前一天的數據,加一個“-”號即可


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM