sql="select top 2 * from a where [type]=1 union all select top 2 * from a where [type]=2 order by id desc"

解决方案 »

  1.   

    select * from test group by type union all select * from test where id not in(select id from test group by type) group by type order by id desc经过测试暂时想出来这个,如果有更优化的可以通知我下PS:楼上给的不太好,如果TYPE有很多种,那就麻烦了
      

  2.   

    select   *   from   test     where     test.id   in   (select   top   N   id   from   test   as   t   where   test.class=t.class   order   by   t.class,t.date   asc)   order   by   test.class,test.date
    楼主你用的是什么数据库,如果你用的不是MYSQL的话这个可以
    要上MYSQL的话,我就不知道了