select distinct pbx_call_id,
first_value(clid) over (partition by pbx_call_id order by callstart) clid,
... -- остальные поля
from calls;
select pbx_call_id,
jsonb_agg(json_build_object('disposition', disposition, 'sip', sip)) as sips
from calls
group by pbx_call_id
Сериал1 Детектив
Сериал1 Боевик
if operation == "USD" or 1: