请问表a
ID TypeID
1   1      
2   1  
3   1
4   2
5   2
6   2
7   2
查出的结果为:
ID TypeID  
1   1
2   1  
4   2
5   2同一类型取2条数据,按照ID排序,谢谢!

解决方案 »

  1.   

    SELECT * from tt5 a where 2>(select count(*) from tt5 where a.TypeID=TypeID and a.id>id)
      

  2.   

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

  3.   

    能得到结果,但是还是不明白
    请问where 2是什么意思
      

  4.   

    select a.TypeID,count(*) from tt5 a left join tt5 b om a.TypeID=b.TypeID and a.id>b.id
    group by a.TypeID
    看看结果
      

  5.   

    SELECT * from tt5 a where (select count(*) from tt5 where a.TypeID=TypeID and a.id>id)<2 
    这样明白了吧