新增资金 累积资金
a1 b1
a2 b2
a3 b3
关系:b1=a1+0;
b2=b1+a2;
b3=b2+a3;
请问下在数据库里面怎么处理这种情况阿
不知累积资金列如何计算?
a1 b1
a2 b2
a3 b3
关系:b1=a1+0;
b2=b1+a2;
b3=b2+a3;
请问下在数据库里面怎么处理这种情况阿
不知累积资金列如何计算?
解决方案 »
- 关于SQL赋权问题 请帮忙解答
- 求SQL语句
- int类型可以自动补0吗?
- nvarchar like 问题
- java里怎么样返回新添加记录的id,id是数据库自动添加的?
- 按日期不同查询数据
- 如何取得相关记录的记录数?
- 局域网内数据复制的问题
- vb中我用ado连接到sqlserver库,现有一打开的connection,在作报表时我需一临时表存放中间数据以进一步处理,如何创建此临时表如何把我当前所得的结果集rsttemp存入此表?请写出具体语句好吗?
- 我要做一个可以分页的东东,请教如何从表中取出某一页的全部记录?
- 这个函数怎么写?(继上一SQL语句)
- sql中两个不同数据库中的不同结构的表之间导数据该怎么办?
(
id int,
A int,
B int
)
insert into @test (id,A)
select 1,100 union all
select 2,90 union all
select 3,50update t
set B=(select isnull(sum(A),0) from @test where id<=t.id)+(select isnull(sum(B),0) from @test where id<t.id)
from @test tselect * from @test
/*
id A B
----------- ----------- -----------
1 100 100
2 90 190
3 50 240
*/
--借用下 夜游神 大哥的測試數據
--set後面的那個+,後面的sum(B)好像衡=0declare @test table
(
id int,
A int,
B int
)
insert into @test (id,A)
select 1,100 union all
select 2,90 union all
select 3,50update t
set B=(select isnull(sum(A),0) from @test where id<=t.id)
from @test tselect * from @test
-------------
id A B
----------- ----------- -----------
1 100 100
2 90 190
3 50 240
或者=(A where id=t.id)+(B where id=t.id-1)
但是我如何赋值给@test呢
或者有针对现成表的方法吗?
----------- ----------- -----------
1 2004 100 100
2 2004 90 190
3 2004 50 240
合计 2004 240
4 2005 100 100
5 2005 90 190
6 2005 50 240
合计 2005 240
对于
id nd(年度) A B
----------- ----------- -----------
1 2004 100 100
2 2004 90 190
3 2004 50 240
我在大家的帮助下能够实现了 谢谢
但是现在我是以年度来分组统计的
这时where id<=t.id
就会失效了,因为2004年的值可能就会加入2005年上去
所以现在主要问题是怎么来确定ID是2004年的还是2005年的
??
from @test t
不过我还想问一下@test与t的关系
为什么我把@test换成具体表之后
B就不会动态变化了 就一直为最终的统计结果了
不是说@test只是测试用表变量吗
但是不用好像就不行了呀?