select a.minClose from(
select min(close) as minClose from (
select close from test order by ID limit 20 offset 当前的ID-1
)
) as a
)
-------------------------------------------方法1select * from (
select
tablename_tmp.*,
@rownum:=@rownum+1 ,
if(time >=DATE_FORMAT(now(),'%Y-%m-%d %H:00') ,@rank:=@rank+1,@rank:=0) as rank
from (
select * from tablename order by time desc
)
tablename_tmp ,
(select @rownum :=0 , @ptime := null ,@rank:=0) a
) a
order by rank desc ,time desc
---------------------------------------方法2
select * from tablename order by
(case when DATE_FORMAT(time ,'%k')=0 then 24 when DATE_FORMAT(time ,'%k')*1>=DATE_FORMAT(now(),'%k')*1 then DATE_FORMAT(time ,'%k') else 25 end) ,time desc
题主测试一下?你这里的24点应该是第二天的00:00:00 。你这样排有什么用处?
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)