博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

SQL SERVER 组内排序

Posted on 2013-07-24 18:59  生命如风  阅读(425)  评论(0编辑  收藏  举报

取出每组的第一个

 

select
*
from (select
* ,RANK ( ) OVER( PARTITION by org order by reportcode asc) PartionNum
from test
) t
where PartionNum = 1

 

rog:分组的字段

reportcode :排序字段