1
在每一行中,我有一列數量(float)和id(int)。所以,我想用連接將庫存中table1到table2數量相同的數量總和相加。例。用連接更新每個sql server行
我的SQL信息
Table 1 Table 2
id quantities id quantities
1 1 1 0
1 2 2 0
2 4 3 0
2 1
3 7
我要總結從表1中的量,並加入到它在表中添加2
期望的結果表2
Table 1 Table 2
id quantities id quantities
1 1 1 3
1 2 2 5
2 4 3 7
2 1
3 7
我嘗試此代碼,但它只添加第一行
update i set quantities=i.quantities+sum(s.rent) from inventory i join temp_rent s on i.id=s.itemid
您的代碼加入的ID和項目ID,但你不顯示,你的表。 – manderson