--创建测试数据
create table books
(
Name nvarchar(50),
Author nvarchar(50),
SaleCount int,
)
insert into books values('C#一点通', '刘君浩', 320)
insert into books values('21天精通C#', '刘君浩', 220)
insert into books values('设计模式C#版', '刘君浩', 120)
insert into books values('SQL基础', '刘君浩', 420)
insert into books values('.net框架', '刘君浩', 60)
insert into books values('SharePoint应用', '刘君浩', 520)
insert into books values('SharePoint开发技术', '刘君浩', 620)
insert into books values('VB.NET设计模式', '萧风', 600)
insert into books values('精通VB.NET', '萧风', 380)
insert into books values('21天精通VB.NET', '萧风', 380)
insert into books values('VB.NET入门经典', '萧风', 580)
insert into books values('VB.NET高级编程', '萧风', 320)
insert into books values('SharePoint入门基础', '萧风', 220)
insert into books values('企业架构', '萧风', 120)
--查询语句
select Author, Name from
(
select a.Author, a.Name, SaleCount, ROW_NUMBER() over (partition by a.Author order by a.Author, a.SaleCount desc) n
from (select Author, Name, sum(SaleCount) SaleCount from books group by Author, Name) a
)
b where n<=5 order by Author, SaleCount desc