以下代碼中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);
相應的如果想查詢前一天的數據,加一個“-”號即可