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
|
SQL> select * from postes ;
POSTE_
------
L01P01
L01P02
L02P01
L02P02
L02P03
SQL> select * from defauts;
DEF_PO DEF_CODE
------ ----------
L02P03 0
L01P02 0
L02P03 1
L01P02 1
L01P02 0
SQL> SELECT DISTINCT postes.l, postes.p,
2 DECODE (def_code,
3 NULL, -1,
4 COUNT (def_code) OVER (PARTITION BY def_poste)
5 ) cpt
6 FROM (SELECT DISTINCT tl.l, tp.p
7 FROM (SELECT SUBSTR (poste_code, 2, 2) l
8 FROM postes) tl,
9 (SELECT SUBSTR (poste_code, 5, 2) p
10 FROM postes) tp) postes,
11 defauts
12 WHERE 'L' || postes.l || 'P' || postes.p = def_poste(+)
13 ORDER BY postes.l, postes.p
14 ;
L P CPT
------ ------ ----------
01 01 -1
01 02 3
01 03 -1
02 01 -1
02 02 -1
02 03 2
6 ligne(s) sélectionnée(s).
SQL> |
Partager