SELECT * from ttl a where 3>(select count(*) from ttl where a.raid=raid and rtime<'你的时间' and a.rtime>rtime)
这样? select t1.*,(select count(*)+1 from reports where raid=t1.raid and rtime > t1.rtime and datcol<'2014-01-16 16:12') as group_id from reports t1 ) a where a.group_id<=3 and datcol<'2014-01-16 16:12' order by a.group_id desc;
where 3>(select count(*) from ttl where a.raid=raid and rtime<'你的时间' and a.rtime>rtime)
select t1.*,(select count(*)+1 from reports where raid=t1.raid and rtime > t1.rtime and datcol<'2014-01-16 16:12') as group_id
from reports t1
) a
where a.group_id<=3 and datcol<'2014-01-16 16:12'
order by a.group_id desc;
正解。里面和外面同时加时间条件达到了,版主厉害,其实,我根据结果也弄出来了,但是自认为sql太差,就放弃了。呵呵