日期:2014-05-17 浏览次数:20732 次
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-05-14 14:03:53
-- Version:
-- Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64)
-- Jun 17 2011 00:54:03
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1, v.721)
--
----------------------------
--> 测试数据:[T1]
if object_id('[T1]') is not null drop table [T1]
go
create table [T1]([Id] int,[A] int)
insert [T1]
select 1,1 union all
select 2,3 union all
select 3,6
--------------开始查询--------------------------
select *,wg=(SELECT SUM(A) FROM [T1] WHERE a.id>=id)
from [T1] a
----------------结果----------------------------
/*
Id A wg
----------- ----------- -----------
1 1 1
2 3 4
3 6 10
*/