select id=identity(int,1,1),* into #t from pf_ckmx order by 单位select * from #t a where (select count(*) from #t where 单位=a.单位 and id<=a.id)<=10
select * from pf_ckmx a where ID in(select top 10 ID from pf_ckmx where 单位=a.单位)
经论证yesyesyes() 是对的!呵呵!
declare @str nvarchar(4000) set @str='' select @str=@str+'select top 10 * from pf_ckmx where unit=''' +unit + ''' union all ' from pf_ckmx group by unit select @str=left(@str,len(@str)-10) exec(@str)
from #t a
where (select count(*) from #t where 单位=a.单位 and id<=a.id)<=10
where ID in(select top 10 ID from pf_ckmx where 单位=a.单位)
set @str=''
select @str=@str+'select top 10 * from pf_ckmx where unit=''' +unit + ''' union all ' from pf_ckmx group by unit
select @str=left(@str,len(@str)-10)
exec(@str)