1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| WITH x AS
(SELECT DISTINCT (t1.id), t2.col1, t2.col2, t3.filiere1, t3.filiere2,t3.periode
FROM
(SELECT DISTINCT (y.id) FROM TABLE y) t1,
table2 t2,
matable t3
WHERE t1.id = t2.id
AND t1.id = t3.id
AND t2.id= t3.id)
SELECT x.id,x.col1, x.col2, x.filiere1, x.filiere2, x.periode
max(case when x.periode = 'p1' then x.filiere1 end) AS filiere1_P1,
max(case when x.periode = 'p2' then x.filiere1 end) AS filiere1_P2,
max(case when x.periode = 'p1' then x.filiere2 end) AS filiere2_P1,
max(case when x.periode = 'p2' then x.filiere2 end) AS filiere2_P2
FROM x
group by x.id,x.col1, x.col2, x.filiere1, x.filiere2, x.periode |
Partager