每个分类取5条, 这样的SQL如何写??

CREATE TABLE table1
(
    [ID] [bigint] IDENTITY(1,1) NOT NULL,
    [Name] [nvarchar](128) NOT NULL,
    [class] int not null,
    [date] datetime not null
)




/*  */
select id,name,class,date from(
select id,name,class,date ,row_number() over(partition by class order by date desc)
as rowindex from table1)a
where rowindex<=5

 

posted on 2012-01-06 10:19  卡域克  阅读(229)  评论(0)    收藏  举报