日期:2014-05-18  浏览次数:20612 次

求救~~~~~
表   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 行受影响)