update public.consultant set avg_score = 1 where agent_no = 'A183619275'; update public.consultant set avg_score = 2 where agent_no = 'AGAM11249699'; update public.consultant set avg_score = 3 where agent_no = 'Z152717443'; update public.consultant set avg_score = 4 where agent_no = 'D265260662'; update public.consultant set avg_score = 5 where agent_no = 'AG0109051204'; update public.consultant set avg_score = 1 where agent_no = 'B282677963'; update public.consultant set avg_score = 2 where agent_no = 'AG0101234567'; update public.consultant set avg_score = 3 where agent_no = 'X147309614'; update public.consultant set avg_score = 4 where agent_no = 'J149388015'; update public.consultant set avg_score = 5 where agent_no = 'R221444250'; do $$ declare avg_row record; begin for avg_row in select round(cast(avg(score) as numeric), 1) as avg_score, agent_no from public.satisfaction where "type" = 'APPOINTMENT' and score is not null group by agent_no loop update public.consultant set avg_score = avg_row.avg_score where agent_no = avg_row.agent_no; end loop; end $$