日期:2014-05-17 浏览次数:20434 次
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-01-26 11:48:25
-- Version:
-- Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
-- Dec 28 2012 20:23:12
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
--
----------------------------------------------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([FieldName] varchar(5))
insert [huang]
select 'A0004' union all
select 'A0005' union all
select 'A0005' union all
select 'A0005' union all
select 'A0006' union all
select 'A0006' union all
select 'A0006'
--------------开始查询--------------------------
select ROW_NUMBER()OVER(PARTITION BY [FieldName] ORDER BY [FieldName])number,* from [huang]
----------------结果----------------------------
/*
number FieldName
-------------------- ---------
1 A0004
1 A0005
2 A0005
3 A0005
1 A0006
2 A0006
3 A0006
*/