1 2 3 4 5 6 7 8 9 10 11 12 13 14
| with
personne as (select 1 id, 'P1' nom from dual union all
select 2, 'P2' from dual),
voiture as (select 'C1' voiture, to_date('02/05/2011','DD/MM/YYYY') dte, 1 id_p from dual union all
select 'C2', to_date('03/01/2010','DD/MM/YYYY'), 1 from dual union all
select 'C4', to_date('02/05/2011','DD/MM/YYYY'), 1 from dual union all
select 'C2', to_date('02/05/2010','DD/MM/YYYY'), 2 from dual union all
select 'C3', to_date('02/05/2011','DD/MM/YYYY'), 2 from dual)
select
p.nom,
max(v.voiture) keep(dense_rank first order by v.dte desc) voiture
from personne p
left join voiture v on v.id_p = p.id
group by p.nom; |
Partager