注意:是從當前時間開始獲取24前的資料,不是前一天
需要用到mysql中的幾個函式:
now()獲取當前時間
timediff()計算兩個時間的差
timediff(expr1,expr2)
timediff()返回 expr1。expr2表示為乙個時間值。expr1 和 expr2 是時間或日期和時間的表達,但兩者都必須是同一型別。
mysql> select timediff('1997-12-31 23:59:59.000001',
-> '1997-12-30 01:01:01.000002');
| timediff('1997-12-31 23:59:59.000001'..... |
| 46:58:57.999999 |
1 row in set (0.00 sec)
3.獲取時間差小時部分
hour(time)
返回時間的小時部分。返回值的範圍為0至23的小時值。然而,time值的範圍實際上要大得多,所以hour可以返回大於23的值。
mysql> select hour('10:05:03');
| hour('10:05:03') |
| 10 |
1 row in set (0.00 sec)
最後拼裝的條件
hour( timediff( now(), enter_time) ) > 24
mysql中如何查詢最近24小時 top n查詢
mysql中如何查詢最近24小時 where visittime now interval 1 hour 昨天 where visittime between curdate interval 1 day and curdate 最近7天 where visittime between curdat...
mysql中如何查詢最近24小時 top n查詢
mysql中如何查詢最近24小時 where visittime now interval 1 hour 昨天 where visittime between curdate interval 1 day and curdate 最近7天 where visittime between curdat...
mysql中如何查詢最近24小時 top n查詢
mysql中如何查詢最近24小時 where visittime now interval 1 hour 昨天 where visittime between curdate interval 1 day and curdate 最近7天 where visittime between curdat...