Hi everyone!
I have a problem and I can't figure out how to solve it, so I would appreciate any help.
1. I need to check each row in OLD TABLE, look into HELP TABLE for NEW_ID (if exists) and create new ID in NEW TABLE
2. Then I need sum all values that belong to NEW_ID and insert into NEW TABLE with NEW_ID
HELP TABLE
[TABLE="width: 200"]
<tbody>[TR]
[TD]NEW_ID[/TD]
[TD]OLD_ID_1[/TD]
[TD]OLD_ID_2[/TD]
[TD]OLD_ID_3[/TD]
[TD]OLD_ID_4[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]11[/TD]
[TD]22[/TD]
[TD]33[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]66[/TD]
[TD]66[/TD]
[TD]88[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]77[/TD]
[TD]77[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]44[/TD]
[TD]55[/TD]
[TD]88[/TD]
[TD]99[/TD]
[/TR]
</tbody>[/TABLE]
OLD TABLE
[TABLE="width: 200"]
<tbody>[TR]
[TD]ID[/TD]
[TD]VALUE[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]66[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]22[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]88[/TD]
[TD]9[/TD]
[/TR]
[TR]
[TD]33[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]77[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]99[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]55[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]44[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]88[/TD]
[TD]7[/TD]
[/TR]
</tbody>[/TABLE]
NEW TABLE
[TABLE="width: 200"]
<tbody>[TR]
[TD]ID[/TD]
[TD]VALUE[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]12[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]13[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]2[/TD]
[/TR]
</tbody>[/TABLE]
I have a problem and I can't figure out how to solve it, so I would appreciate any help.
1. I need to check each row in OLD TABLE, look into HELP TABLE for NEW_ID (if exists) and create new ID in NEW TABLE
2. Then I need sum all values that belong to NEW_ID and insert into NEW TABLE with NEW_ID
HELP TABLE
[TABLE="width: 200"]
<tbody>[TR]
[TD]NEW_ID[/TD]
[TD]OLD_ID_1[/TD]
[TD]OLD_ID_2[/TD]
[TD]OLD_ID_3[/TD]
[TD]OLD_ID_4[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]11[/TD]
[TD]22[/TD]
[TD]33[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]66[/TD]
[TD]66[/TD]
[TD]88[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]77[/TD]
[TD]77[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]44[/TD]
[TD]55[/TD]
[TD]88[/TD]
[TD]99[/TD]
[/TR]
</tbody>[/TABLE]
OLD TABLE
[TABLE="width: 200"]
<tbody>[TR]
[TD]ID[/TD]
[TD]VALUE[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]66[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]22[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]88[/TD]
[TD]9[/TD]
[/TR]
[TR]
[TD]33[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]77[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]99[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]55[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]44[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]88[/TD]
[TD]7[/TD]
[/TR]
</tbody>[/TABLE]
NEW TABLE
[TABLE="width: 200"]
<tbody>[TR]
[TD]ID[/TD]
[TD]VALUE[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]12[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]13[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]2[/TD]
[/TR]
</tbody>[/TABLE]