日期:2014-05-18 浏览次数:20492 次
;with AcHerat as ( select *,rid=row_number() over (partition by id2 order by id1) from tb ) select id1,id2 from AcHerat where rid <= 2 -- 就是n
------解决方案--------------------
select id1,id2 from ( select row_number()over(partition by id2 order by id1)rn,* )t where rn<=2
------解决方案--------------------
--2000 select * from tb t where (select count(*) from tb where id2 = t.id2 and id1 <= t.id1) <= 2 -- 就是n