我想取数据库里24小时之内的记录并按点击次数排序,下面的sql怎么不行:select * from index_message_middle where DATEDIFF("h",TIME,GETDATE())<24 order by bits descTIME 是数据库记录发布日期的字段,bits是点击次数
我想取数据库里24小时之内的记录并按点击次数排序,下面的sql怎么不行:select * from index_message_middle where DATEDIFF("h",TIME,GETDATE())<24 order by bits descTIME 是数据库记录发布日期的字段,bits是点击次数
2, 使用 date_sub进行减24小时select *
from index_message_middle
where `TIME` > DATE_SUB(NOW(),INTERVAL 24 HOUR)
order by bits desc
注意TIMEDIFF的方向。及time关键字。select *
from index_message_middle
where hour(TIMEDIFF(NOW(),`TIME`)) <24
order by bits desc或者select *
from index_message_middle
where TIMEDIFF(NOW(),`TIME`)<240000
order by bits desc