mysql 獲取某個時間段的最近一條資料

2021-10-09 01:31:19 字數 726 閱讀 8033

一 **

我需要獲取rating_date最近的一條資料

select  * from rating_basic_info where company_id = 11501 order by abs(datediff(rating_date,'2020-08-03')) asc limit 0,1

效果圖:

上面是**

select  * from rating_basic_info where company_id = 11501 order by abs(datediff(rating_date,'2020-08-03')) asc 

這是效果圖:

也就是說:我要獲取 8月3號的資料的話,取第二條資料就行了

因為:datediff

datediff() 函式返回兩個日期之間的天數。

所以如果一定要精確到小時的話,可以先去重,再進行上面的sql語句。

mysql 查詢某個時間段的資料

今天 select from 表名 where to days 時間欄位名 to days now 昨天 包括昨天和今天的資料 select from 表名 where to days now to days 時間欄位名 1 昨天 只包括昨天 select from 表名 where datedif...

shell獲取某個時間段的nginx日誌內容

shell獲取某個時間段的nginx日誌內容 小醉90s 2014 04 06 16 40 36 15297 收藏 1 分類專欄 linux 版權從nginx日誌中獲取2014 04 01日 21 30至21 50的日誌內容 方法1 sed cat web.log egrep 01 apr 2014...

ORACLE獲取某個時間段之間的月份列表

oracle獲取某個時間段之間的月份列表 獲取某個時間段之間的月份列表 示例返回2009 03到2010 03之間的月份列表 select to char add months to date 2009 03 yyyy mm rownum 1 yyyy mm day id from dual con...