读书人

求救~该怎么处理

发布时间: 2012-02-21 16:26:23 作者: rapoo

求救~~~~~
表 A 结构如下
ID B
1 2.1
2 1.2
3 3.5

要求查询结果如下
id sum
1 2.1
2 3.3
3 6.8
语句怎么写? 我这没有SQLServer,
我是个新手,没分了。

[解决办法]
declare @ta table(ID int, B decimal(15,2))
insert @ta select 1, 2.1
union all select 2, 1.2
union all select 3, 3.5

select id,
[sum]=(select sum(b)from @ta where id!> a.id)
from @ta a

(3 行受影响)
id sum
----------- ---------------------------------------
1 2.10
2 3.30
3 6.80

(3 行受影响)

读书人网 >SQL Server

热点推荐