1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| With MaTable as
(
select 1 as Loc, 1 as Occ, '01/01/2011' as Date from dual union all
select 1 , 2 , '01/03/2011' from dual union all
select 1 , 3 , '01/02/2012' from dual union all
select 2 , 1 , '01/01/2011' from dual union all
select 2 , 2 , null from dual union all
select 3 , 1 , '01/01/2011' from dual union all
select 3 , 2 , '01/02/2012' from dual
)
, SR as
(
select Loc, Occ, Date
, row_number() over(partition by Loc order by Occ desc) as rn
from MaTable
)
select Loc, Occ, Date
from SR
where rn = 1
and Date is not null
Loc Occ Date
----------- ----------- ----------
1 3 01/02/2012
3 2 01/02/2012 |
Partager