mysql 查询一天之内的数据

时间:2022-08-31 18:26:21

一天时间之内的数据,就是从今天 0时到24时 -- 即第二天0时。

采用 

DATE_SUB(#{time},INTERVAL -1 DAY)
函数来获取time的后24小时的时间。如果time = '2018-3-27 00:00:00',那么该函数得到的值就是
'2018-3-28 00:00:00';


sql:
select t.* from table t where t.time between #{time} and DATE_SUB(#{time},INTERVAL -1 DAY);