日期:2014-05-17 浏览次数:20518 次
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-08-15 17:10:32
-- 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,[YEARS] int,[SX] varchar(6),[HAOMA] varchar(2),[COLOR] varchar(5))
insert [huang]
select 2,2013,'mouse','06','green' union all
select 3,2013,'mouse','18','red' union all
select 4,2013,'mouse','30','red' union all
select 5,2013,'mouse','42','blue' union all
select 6,2013,'cattle','05','green' union all
select 7,2013,'cattle','17','green' union all
select 8,2013,'cattle','29','red' union all
select 9,2013,'cattle','41','blue'
--------------开始查询--------------------------
--select * from [huang]
SELECT *,ROW_NUMBER()OVER(PARTITION BY sx ORDER BY id)pid INTO #t