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 26 27 28 29 30 31
| with t_personne as
(
select 1000 as id_personne, 2 as num_ressource_preferee from dual union all
select 1001 , 3 from dual
)
, t_ressource as
(
select 2000 as id_ressource, 1000 as proprio from dual union all
select 2001 , 1000 from dual union all
select 2002 , 1001 from dual union all
select 2003 , 1001 from dual union all
select 2004 , 1001 from dual
)
, n_ressource as
(
select id_ressource, proprio,
row_number() over(partition by proprio order by id_ressource asc) as rn
from t_ressource
)
select r.id_ressource, r.proprio,
case r.rn when p.num_ressource_preferee then 1 else 0 end as preferee
from n_ressource r
inner join t_personne p
on p.id_personne = r.proprio;
ID_RESSOURCE PROPRIO PREFEREE
2000 1000 0
2001 1000 1
2002 1001 0
2003 1001 0
2004 1001 1 |
Partager