select distinct
a.first_letter_fam,
a.avg_plateg_by_letter
from
(
select
substr(n.c_last_name, 1, 1) as first_letter_fam,
avg(p.n_sum) over (partition by substr(n.c_last_name, 1, 1)) as avg_plateg_by_letter,
(
n_info_cold + n_info_hot
)
as potr_vody,
avg(n_info_cold + n_info_hot) over () as avg_potr_vody_all
from
computation c,
client n,
payment p
where
c.n_client = n.n_client
and
p.n_client = n.n_client
)
a
where
a.potr_vody < a.avg_potr_vody_all
order by a.first_letter_fam