更新语句继续提问。别嫌我烦。答对者每人可得100分。重复不算。(可用分快没了)
表theA
id the1 th2 (注意id可以重复)
1 4 10
1 6 15
2 3 5
3 1 3
表theB
id sum1 sum2 (sum1为表theA的id<=theB.id的所有the1的累加)
1 0 0 (sum2为表theA的id<=theB.id的所有the2的累加)
2 0 0
3 0 0
想能过一条Update语句
得到
id sumNum sumMemory
1 10 25
2 13 30
3 14 33
我知道
Update theB set sum1=(select sum(the1) from theA where theA.id<=theB.id),sum2=(select sum(the2) from theA where theA.id=theB.id)
这样对每一个theB表更新字段都要对theA 表进行一次汇总查询。请问,有没有效率更高的方法?别吐我。