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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| SQL> set sqlblanklines on
SQL> SELECT max(case when num_visite = 1 then Id_medecins end) AS Id_medecins_1,
2 max(case when num_visite = 1 then Id_employe end) AS Id_employe_1,
3 max(case when num_visite = 1 then date_visite end) AS date_visite_1,
4
5 max(case when num_visite = 2 then Id_medecins end) AS Id_medecins_2,
6 max(case when num_visite = 2 then Id_employe end) AS Id_employe_2,
7 max(case when num_visite = 2 then date_visite end) AS date_visite_2
8
9 FROM (SELECT
10 Id_medecins, Id_employe, date_visite, num_visite
11 FROM (SELECT Id_medecins,
12 Id_employe,
13 date_visite,
14 row_number() over (partition BY id_medecin ORDER BY date_visite DESC) AS num_visite
15 FROM TABLE
16 )
17 WHERE num_visite <= 3
18 )
19
20 ;
)
*
ERROR at line 16:
ORA-00906: missing left parenthesis
SQL> 15 from t
SQL> r
1 SELECT max(case when num_visite = 1 then Id_medecins end) AS Id_medecins_1,
2 max(case when num_visite = 1 then Id_employe end) AS Id_employe_1,
3 max(case when num_visite = 1 then date_visite end) AS date_visite_1,
4
5 max(case when num_visite = 2 then Id_medecins end) AS Id_medecins_2,
6 max(case when num_visite = 2 then Id_employe end) AS Id_employe_2,
7 max(case when num_visite = 2 then date_visite end) AS date_visite_2
8
9 FROM (SELECT
10 Id_medecins, Id_employe, date_visite, num_visite
11 FROM (SELECT Id_medecins,
12 Id_employe,
13 date_visite,
14 row_number() over (partition BY id_medecin ORDER BY date_visite DESC) AS num_visite
15 from t
16 )
17 WHERE num_visite <= 3
18 )
19
20*
ID_MEDECINS_1 ID_EMPLOYE_1 DATE_VISITE_1 ID_MEDECINS_2 ID_EMPLOYE_2
------------- ------------ ------------- ------------- ------------
DATE_VISITE_2
------------- |