select * from GCXWHZ a where ZRRID in(select top 2 ZRRID from GCXWHZ where GCXWID=a.GCXWID)

解决方案 »

  1.   

    select * from GCXWHZ a where (select count(1) from GCXWHZ where ZRRID<a.ZRRID)<=2
    order by ZRRID
      

  2.   

    select * from GCXWHZ a where (select count(1) from GCXWHZ where ZRRID<a.ZRRID)<=2
    order by ZRRID
      

  3.   

    大家没明白我的意思,
    我是说每种GCXWID都取两条.也只取两条
    也就是说GCXWHZ可能有1000条,是15种GCXWID的,每种都超过两条以上数据,那么我应该取得是30条数据
      

  4.   

    select * from GCXWHZ where GCXWID in(select top 2 GCXWID from GCXWHZ AS a where a.GCXWID=GCXWHZ.GCXWID)
      

  5.   

    declare @t table(GCXWID INT,ZRRID INT)
    insert @t 
    select 1,1 union all
    select 1,2 union all
    select 1,3 union all
    select 1,4 union all
    select 2,2 union all
    select 2,3 union all
    select 2,4 union all
    select 2,5 union all
    select 3,1 union all
    select 3,2 union all
    select 3,3 union all
    select 3,4 select * from @t a 
    WHERE ZRRID in(select TOP 2 ZRRID FROM @t WHERE GCXWID=a.GCXWID order by ZRRID )/*
    GCXWID  ZRRID
    1 1
    1 2
    2 2
    2 3
    3 1
    3 2
    */
      

  6.   

    declare @GCXWHZ table(GCXWID  int,ZRRID int)insert @GCXWHZ 
    select '1','1' union all
    select '1','2' union all
    select '1','3' union all
    select '1','4' union all
    select '2','7' union all
    select '2','8' union all
    select '2','9' 
    SELECT 
    *
    FROM
    @GCXWHZ a
    WHERE
    ZRRID
    in
    (SELECT Top 2 ZRRID from @GCXWHZ b where b.GCXWID = a.GCXWID)
    ---------------------------------
    1 1
    1 2
    2 7
    2 8