id reporty reportm finace
1 2006 1 xx
2 2006 2 xx
3 2006 3 xx
4 2006 4 xx
5 2006 5 xx
6 2006 6 xx
7 2006 7 xx
8 2006 8 xx
9 2006 9 xx
10 2006 10 xx
11 2006 11 xx
12 2006 12 xx
13 2007 1 xx
14 2007 2 xx
15 2007 3 xx
16 2007 4 xx
.
.
.t2表
id t1_id aa data1 data2 data3
1 1 1 1 2 3
2 1 2 1 2 3
3 1 3 1 2 3
4 1 4 1 2 3
5 2 1 1 2 3
6 2 2 1 2 3
7 2 3 1 2 3
8 2 4 1 2 3
9 3 1 1 2 3
10 3 2 1 2 3
11 3 3 1 2 3
12 3 4 1 2 3
13 4 1 1 2 3
14 4 2 1 2 3
15 4 3 1 2 3
16 4 4 1 2 3
.
.
.要将t2表中的每行data3 更新为 本年的累计数
如果当前月是1 data3数值就为当前月
数值>2的 data3数值就是从本年的1至当前月的累计数这个update语句应该怎么写?能不能不用函数实现,因为
更新的数目很多,每个都要写函数的话函数太多了
不知道累计哪个字段,我假设是累计data1+data2 update a
set data3=(select sum(a1.data1+a1.data2) from t2 a1,t1 b1 where a1.aa=a.aa and a1.t1_id=b1.id and b1.reporty=b.reporty and b1.reportm<=b.reportm )
from t2 a,t1 b
where a.t1_id=b.id