I know this question has asked many times in SO,but i couldn\'t figure out my exact problem.
I am using the following code to get the data from the database(Table1)
You can achieve your goal with pure SQL it is faster and better from architecture point of View because all logic will be in one SQL transaction
REPLACE INTO table_where_to_put SELECT *, (totalmatchedscore/totalingredients) as average FROM table_with_input_data
Use REPLACE OR UPDATE