用最新时间排序,然后最新的前5条记录不要查询,查询第6条之后的记录用一条sql怎么实现?

解决方案 »

  1.   

    可考慮用存儲過程來實現:
    DELIMITER $$DROP PROCEDURE IF EXISTS `db`.`sp` $$
    CREATE PROCEDURE `sp`()
    begin  prepare stmt from 'Select * from table limit 6,?' ;  select count(*) into @inta  from table;  execute stmt using @inta; end $$DELIMITER ;
      

  2.   

    你要不用存储过程只能这样写了。
    select count(*) from 你的表 into @cnt;
    select * from 你的表 where 1 = 1 order by 时间字段 desc limit 6,@cnt;
      

  3.   

    select * from table where ID not in ( select * from (select ID from table order by time  limit 5)  as t) order by timeid是主键。
      

  4.   

    @cnt是什么?我还看不明白这样的sql,等我明天试试,not in不行的,用了limit它就不支持in语法了。
      

  5.   

    select * from 你的表 where 1 order by 时间字段 desc limit 6,9999999
      

  6.   

    select   *   from   你的表   where  ID not in(select top 5 ID from 你的表 )   order   by   时间字段   desc