1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| with matable (commande, flag1, flag2, date1, heure1) as
(
select '001', 1, 1, '01/01', 1530 from dual union all
select '001', 1, 2, '02/01', 1600 from dual union all
select '001', 2, 2, '02/01', 1715 from dual union all
select '002', 1, 1, '02/01', 1530 from dual union all
select '002', 1, 2, '03/01', 1005 from dual union all
select '002', 2, 2, '03/01', 1015 from dual
)
select commande
, max(case when flag1 = 1 and flag2 = 1 then date1 end) as date_fg_11
, max(case when flag1 = 1 and flag2 = 1 then heure1 end) as heure_fg_11
, max(case when flag1 = 1 and flag2 = 2 then date1 end) as date_fg_12
, max(case when flag1 = 1 and flag2 = 2 then heure1 end) as heure_fg_12
, max(case when flag1 = 2 and flag2 = 2 then date1 end) as date_fg_22
, max(case when flag1 = 2 and flag2 = 2 then heure1 end) as heure_fg_22
from matable
group by commande
order by commande asc;
COMMANDE DATE_FG_11 HEURE_FG_11 DATE_FG_12 HEURE_FG_12 DATE_FG_22 HEURE_FG_22
-------- ---------- ----------- ---------- ----------- ---------- -----------
001 01/01 1530 02/01 1600 02/01 1715
002 02/01 1530 03/01 1005 03/01 1015 |
Partager