您的位置首页百科快答

从mysql取出值小于

从mysql取出值小于

的有关信息介绍如下:

从mysql取出值小于

--一个语句还真想不出怎么做,

--建一个临时表,把下面查出的数据保存在里面,按rank分组,having count(*)>1 ,找出记录数大于1的rank就是你要的记录

select name,dtime,rank,ptime,ptime2 from(

select cg_tmp.*, @rownum :=@rownum + 1,

if(TIMESTAMPDIFF(MINUTE, @ptime,cg_tmp.dtime)<5,@rank:=@rank ,@rank:=@rank+1) as rank,

@ptime2:=cg_tmp.dtime as ptime2,

if(TIMESTAMPDIFF(MINUTE, @ptime,cg_tmp.dtime)<5,@ptime=null,@ptime:=@ptime2) as ptime

from

(

select * from `timerecord` order by dtime

) cg_tmp,

(select @rownum :=0 , @ptime := null ,@rank:=0,@rank2:=0,@ptime2 := null) a

) result

我见其中包含这句:

if(TIMESTAMPDIFF(MINUTE, @ptime,cg_tmp.dtime)<5这里的5就是时间相差小于5分钟,后面有个小于号看到没