update MaterialEntry set totalprice = (select sum(cost*amount) from MaterialEntryItem where materialEntry_id=MaterialEntry.id) where totalPrice is null;