0
I have this query:
with chave (data_utc, matricula) AS (
select de.data_utc, de.matricula from dep_assop.dedalo de
group by de.data_utc, de.matricula
union
select oa.data_utc, oa.matricula from dep_assop.ocorrencias_aeronauticas oa
group by oa.data_utc, oa.matricula
union
select ec.data_utc, ec.matricula from dep_assop.eccairs ec
group by ec.data_utc, ec.matricula
)
select
ch.data_utc,
ch.matricula,
oa.classificacao classificacao_anac,
ec.classificacao classificacao_eccairs,
de.classificacao classificacao_dedalo,
listagg(oa.tipo, ', ') within group (order by oa.tipo) ADREP_ANAC,
listagg(ec.tipo, ', ') within group (order by ec.tipo) ADREP_ECCAIRS,
listagg(de.tipo, ', ') within group (order by de.tipo) ADREP_DEDALO
from
chave ch
full join eccairs ec on ec.data_utc=ch.data_utc and ec.matricula=ch.matricula
full join dedalo de on de.data_utc=ch.data_utc and de.matricula=ch.matricula
full join ocorrencias_aeronauticas oa on oa.data_utc=ch.data_utc and oa.matricula=ch.matricula
group by
ch.data_utc, ch.matricula, oa.classificacao, ec.classificacao, de.classificacao
What should be returned:
28/10/10 | PPGOZ | Serious incident | null | Serious incident | LOC-G, RE | null | LOC-G, RE
Why this? Since I am grouping everything from the union of the tables and then when I have my key table defined.
In the listgg you do the distinct before otherwise this happens , type a subselect as table , at least on 11 , at 12 do not know if changed.
– Motta
It would be a sub query select distinct listagg .... ?
– Otávio