在mysql表中,有10000行数据,根据时间字段可以分成20个组,如何通过一句取得每个20组中的第一行以及最后一行数据?数据按照id的自增长排序,id为主键 谢谢

解决方案 »

  1.   

    参考下贴中的多种方法http://topic.csdn.net/u/20091231/16/2f268740-391e-40f2-a15e-f243b2c925ab.html
    [征集]分组取最大N条记录方法征集,及散分....
      

  2.   

    select *
    from tb A
    where not exists (select 1 from tb where A.时间字段=时间字段  and A.id>id)
    union all
    select *
    from tb A
    where not exists (select 1 from tb where A.时间字段=时间字段  and A.id<id)
      

  3.   

    贴建表及插入记录的SQL,及要求结果出来看看