I´m learning PL SQL and I ran into a wall...
And I want to get the Tripulante that has the most nHorasEfectuadas on each TipoAviao. (The id of the crew that has the most number of hours in each plane type).
I tried this :
SELECT T.IDTRIPULANTE, A.IDTIPOAVIAO, H.NHORASEFETUADAS
FROM TRIPULANTE T, HORASVOO H, TIPOAVIAO A
WHERE T.IDTRIPULANTE=H.IDTRIPULANTE
and H.IDTIPOAVIAO=A.IDTIPOAVIAO
and H.NHORASEFETUADAS = (select distinct max(o.NHORASEFETUADAS)
FROM HORASVOO o
WHERE o.IDTRIPULANTE = T.IDTRIPULANTE)
ORDER BY A.IDTIPOAVIAO;
But its returning ALL of the Tripulantes...(Only have 10)
Anything I'm doing wrong?
Thanks!

