日期:2014-05-18 浏览次数:20430 次
declare @type table ( tid int, tname varchar(50) ) declare @news table ( nid INT IDENTITY (1,1), tid int, news varchar(100) ) insert into @type values(1,'A') insert into @type values(2,'B') insert into @type values(3,'C') insert into @news values(1,'xxx1') insert into @news values(1,'xxx2') insert into @news values(1,'xxx3') insert into @news values(1,'xxx4') insert into @news values(1,'xxx5') insert into @news values(1,'xxx6') insert into @news values(1,'xxx7') insert into @news values(2,'xxxa1') insert into @news values(2,'xxxb2') insert into @news values(2,'xxxc3') insert into @news values(2,'xxxd4') insert into @news values(2,'xxxe5') insert into @news values(2,'xxxf6') insert into @news values(2,'xxxf7') select * from @news ns where ns.nid in (select top 5 nid from @news n where n.tid = ns.tid)