日期:2014-05-16 浏览次数:20575 次
----------------------------------------------------------------
-- Author :DBA_HuangZJ(发粪涂墙)
-- Date :2014-05-07 16:56:47
-- Version:
-- Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)
-- Apr 2 2010 15:48:46
-- Copyright (c) Microsoft Corporation
-- Enterprise 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,[name] nvarchar(2),[value] int)
insert [huang]
select 1,'a',1 union all
select 2,'a',2 union all
select 3,'b',3
--------------生成数据--------------------------
select * from [huang]
;WITH cte AS (SELECT name,value,ROW_NUMBER()OVER(PARTITION BY name ORDER BY id)New_id FROM huang )
UPDATE cte
SET value=value+1024
WHERE New_id=1
SELECT * FROM huang
----------------结果----------------------------
/*
id name value
----------- ---- -----------
1 a 1
2 a 2
3 b 3
(3 row(s) affected)
(2 row(s) affected)
id name value
----------- ---- -----------
1 a 1025
2 a 2
3 b 1027
*/