to txlicenhe(马可):
我用您的:
select * from table a where X in ('分类1','分类2','分类3') and X in
(select top 3 X from table where X=a.X order by X desc)
order by X
select top 3 * into #temp from table where 分类 = '分类1' order by id desc
insert into #temp select top 3 * from table where 分类 = '分类2' order by id desc
insert into #temp select top 3 * from table where 分类 = '分类3' order by id desc
select * from #temp
drop table #temp
select *, identity(int,1,1) id into #t from [table] where 分类 in ('分类1','分类2','分类3')
select * from #t as A where id in (select top 3 id from #t where 分类 = A.分类 order by id desc)
select *, identity(int,1,1) id into #t from [table] where 分类 in ('分类1','分类2','分类3')
select * from #t as A where id in (select top 3 id from #t where 分类 = A.分类)