不能用视图,用存储过程:create proc pr_Query
as
select a,b,c,IDENTITY(int,1,1) as id into # from abcselect a,b,c
from # a
where (select count(*) from # where a=a.a and id<=a.id)<=2
order by a,iddrop table #
go
as
select a,b,c,IDENTITY(int,1,1) as id into # from abcselect a,b,c
from # a
where (select count(*) from # where a=a.a and id<=a.id)<=2
order by a,iddrop table #
go
from #
FROM contract_basic aa where shouxf in (select top 2 shouxf from contract_basic where contractid = aa.contractid )
可以想要多少條就top多少條