0
I have 3 aircraft tables, occurrence and aeronave_occurrence, I need to know if the same aircraft was present in any event in the last 2 months of the data_utc back, and how many aircraft were present.
Information in the tables: aircraft (id_aircraft, registration); occurrence (id_occurrence, data_utc); aeronave_occurrence(id_aeronave_occurrence, id_aircraft, id_occurrence)
I’m lost in this query, I don’t know where to go HELP:
SELECT
a.matricula,
count(a.matricula)
FROM
aeronave a
JOIN aeronave_ocorrencia ao ON a.id_aeronave = ao.id_aeronave
JOIN ocorrencia o ON ao.id_ocorrencia = o.id_ocorrencia
WHERE
o.data_utc > ADD_MONTHS(o.data_utc , -2 )
GROUP BY
a.matricula
Put as a condition
o.data_utc > ADD_MONTHS(SYSDATE , -2 )
.– anonimo
or.data_utc >= TRUNC(ADD_MONTHS(SYSDATE , -2 ),'MM') taking into account the beginning of the month , which means "last 2 months"
– Motta
"last 2 months" means the last 2 months taking as reference the data_utc of occurrence.
– Otávio
my doubt would be , date today 14/8 , would be 14/7 to 14/8 , from 1/7 to 14/8 ,... I understand as 1/7 to 14/8
– Motta
If data_utc = 14/08, then it would be 14/06 to 14/08 and so on.... See that data_utc are several distinct dates, it can be 12/08, 03/03...
– Otávio