select
tvc.contract_id,
c.number,
count(*) as coeff_count
from prod_line.table_vesting_coeffs tvc
join ourpension.contract c
on c.id = tvc.contract_id
where tvc.contract_id is not null
group by
tvc.contract_id,
c.number
order by tvc.contract_id desc
limit 20;