码迷,mamicode.com
首页 > 编程语言 > 详细

Rank 获取排序的序号

时间:2016-06-18 23:55:34      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

Select *,RANK() over (partition by 分组列名 order by 排序列名) as rn from [Table]

 

例如:获取按…分组的按…排序的每组的前2条记录

select Table1.* from

(

select *,RANK()
over (partition by a.列1,a.列2, order by a.列3) as rn
from Table1

) as Table2 

where rn < 3

Rank 获取排序的序号

标签:

原文地址:http://www.cnblogs.com/xieyuanzheng/p/5597067.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!