Это мой запрос, чтобы получить пять лучших строк в зависимости от приоритета.
Если доступно только два имени контакта - скажем, name1
и name2
- я хочу, чтобы вывод был name1,name2,,,
.
Но я получаю name1,name2
.
Как я могу получить запятые?
with cte as (
select pc.person_number
,pc.contact_names
,pc.contact_type
,case when pl.relation='parent' then 'a'
when pl.relation='children' then 'b'
when pl.relation='sibling' then 'c'
end as priority
from person_contact pc
,person_lookup pl
where pc.contact_type=pl.contact_type
)
select person_number
,listagg(contact_names,',')
WITHIN GROUP (ORDER BY priority) contact_name
from cte
group by person_number
fetch first 5 rows only