Combining some items within an aggregated list in SQL - TechRepublic
Question
September 23, 2015 at 05:39 PM
john.a.wills

Combining some items within an aggregated list in SQL

by john.a.wills . Updated 10 years, 8 months ago

I have this column in an SQL query (within Argos, but that is perhaps not germane):
ListAgg (high.SPRTELE_PHONE_AREA || high.SPRTELE_PHONE_NUMBER || ‘||’
|| case high.SPRTELE_TELE_CODE when ‘HM’ then ‘2’
when ‘CE’ then ‘2’
when ‘TX’ then ‘1’
else
‘mistake’
end
|| ‘|’ || nvl (high.SPRTELE_CTRY_CODE_PHONE, ‘1’)
|| ‘|’ || STVTELE.STVTELE_DESC, ‘;’) within group (order by sprtele_ctry_code_phone, sprtele_phone_area, sprtele_phone_number)
It gives me a list of telephone numbers with related data for each number. When the _tele_code handling yields a ‘1’ and a ‘2’ for the same telephone number I want to have only one item in the list with value ‘3’. How do I set about this? Do I have to nest ListAgg in some way? Or is there a less scruffy solution?

This discussion is locked

All Comments