declare cursor custs is select ROUND(SUM(item_qty)/count(distinct tran_id), 3) as avg, consumer_id from tranit_tran_item group by consumer_id; begin for cust in custs loop update customers set avgtransvol = cust.avg where consumer_id = cust.consumer_id; end loop; end;