1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
WITH T2_BIS AS (
SELECT
id,idsoc,annee,ca_partiel,
rank() over (PARTITION BY idsoc,annee ORDER BY id) rang
FROM T2)
SELECT
T1.*,
T2_1.ca_partiel ca1,
T2_2.ca_partiel ca2,
T2_3.ca_partiel ca3
FROM
T1 left outer join (SELECT * FROM T2_BIS WHERE rang = 1) T2_1 ON T1.IDSOC = T2_1.IDSOC AND T1.ANNEE = T2_1.ANNEE
left outer join (SELECT * FROM T2_BIS WHERE rang = 2) T2_2 ON T1.IDSOC = T2_2.IDSOC AND T1.ANNEE = T2_2.ANNEE
left outer join (SELECT * FROM T2_BIS WHERE rang = 3) T2_3 ON T1.IDSOC = T2_3.IDSOC AND T1.ANNEE = T2_3.ANNEE |
Partager