文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>MsSql分区函数的使用

MsSql分区函数的使用

时间:2010-09-17  来源:幽境仼孓

例1:根据Northwind数据库,要求查询出每个员工最近的三条订单数据

代码 1 with result
2 as
3 (
4    select row_number()over(partition by o.employeeID order by o.orderdate desc )as row ,e.lastName,e.FirstName,o.OrderID
5    from employees e join orders o on e.employeeID=o.employeeID
6 ) 

8 select * from result where row<=3

 

 

例2: 

代码 create table Student  --学生成绩表
(
 id int,  --主键
 Grade int, --班级
 Score int --分数
)
insert Student  select 1,1,88
union all select 2,1,66
union all select 3,1,75
union all select 4,2,30
union all select 5,2,70
union all select 6,2,80
union all select 7,2,60
union all select 8,3,90
union all select 9,3,70
union all select 10,3,80

select * from student


select top 3 with ties * from  student order by score desc//前三名

select *,row_number() over(partition by grade order by score desc)as '名次' from student

 

 

相关阅读 更多 +
排行榜 更多 +
罗马战争与防御

罗马战争与防御

策略塔防 下载
3d坦克突击最新版

3d坦克突击最新版

飞行射击 下载
3d子弹先生射击模拟器安卓版

3d子弹先生射击模拟器安卓版

飞行射击 下载