我有一个像
这样的领域的桌子TimeStamp | Feild1 | Feild 2
--------------------------------------
1902909002 | xyddtz | 233447
1902909003 | xytzff | 233442
1902909005 | xytzdd | 233443
1902909007 | xytzdd | 233443
1902909009 | xytsqz | 233436
现在我想查询它并获取1902909002和1902909007之间的记录,这些记录可以通过以下方式轻松完成:
Select * from table where timestamp > 1902909001 AND timestamp < 1902909008
但我想做的另外两件事是:
答案 0 :(得分:1)
尝试此查询
select * from(
select @rn:=if(@rn < rid, rid, @rn) as rn, rid, timestamp, feild1, feild2
from
(select @rn:=@rn+1 as rId, tbl.*
from tbl
join
(select @rn:=0) tmp
where timestamp between 1902909002 and 1902909024 order by rid desc)a
join
(select @rn:=0)tmp)tmp
where rid%(rn div 6)=0
答案 1 :(得分:0)
尝试这一点(两个查询在同一个mysql会话中执行是至关重要的):
SET @c:=0;
SELECT
*
FROM (
SELECT
* ,
@c:=@c+1 as counter
FROM
table
WHERE
timestamp > 1902909001
AND timestamp < 1902909008
) as tmp
WHERE
counter % 20 =1;