大概有一个这样的表
cid names,types
第三个字段是分类  
求第一分类的前N条数据  cid不一定连续

解决方案 »

  1.   


    select * from tb t where cid in(select top n cid from tb where types=t.types order by cid)
      

  2.   

    --2005select * from (select rn=row_number()over(partition by types order by cid),* from tb) t where rn<=n
      

  3.   

    SELECT * FROM @a a WHERE cid in(SELECT TOP 3 htrq FROM @a WHERE types=a.types ORDER BY cid)
      

  4.   

    select * 
    from tb t 
    whre (select count(*)from tb where types=t.types and cid>t.cid)<3
      

  5.   

    select * 
    from tb t 
    where (select count(*)from tb where types=t.types and cid>t.cid)<3