日期:2014-05-17 浏览次数:20458 次
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-10-14 15:21:41
-- Version:
-- Microsoft SQL Server 2014 (CTP1) - 11.0.9120.5 (X64)
-- Jun 10 2013 20:09:10
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([id] int)
insert [huang]
select 1 union all
select 1 union all
select 2 union all
select 2 union all
select 3 union all
select 3 union all
select 3 union all
select 4 union all
select 4 union all
select 4 union all
select 4 union all
select 4 union all
select 5 union all
select 5
--------------开始查询--------------------------
select *-- ,ROW_NUMBER() OVER (PARTITION BY id ORDER BY id)
from [huang]
ORDER BY ROW_NUMBER() OVER (PARTITION BY id ORDER BY id),id
----------------结果----------------------------
/*
id
-----------
1
2
3
4
5
1
2
3
4
5
3
4
4
4
*/