Bonjour,
J'utilise Oracle 10g et je suis en train de faire une requête relativement compliquée mais je suis bloqué à un point. Je le résume ici. C'est un exemple débile au niveau du sens des requêtes imbriqués car on se répète mais qui illustre bien mon problème.
Rassurez vous, dans ma requête, je n'ai pas ce genre de répétition.
Pour une requête du type :
Ma question est la suivante : Comment faire pour éviter d'effectuer à chaque fois cette sous-requêteCode:
1
2
3
4
5
6
7
8 SELECT age FROM ( SELECT * FROM employes WHERE age > 25 ) WHERE age > (SELECT * FROM employes WHERE age > 25) AND age > (SELECT * FROM employes WHERE age > 25)
?Code:SELECT * FROM employes WHERE age > 25
Pour les cheveronnés , voici ma requête :
On voit bien ici que l'on repête la requêteCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 SELECT SUM(rec.LONGUEUR) FROM G_REC rec, ( SELECT ID_STRUCTURE FROM ( SELECT rownum AS numero, structure.*, rang FROM g_structures structure START WITH structure.id_structure_pere = 0 CONNECT BY structure.id_structure_pere = PRIOR structure.id_structure ORDER SIBLINGS BY structure.rang ) resultats WHERE numero >= ( SELECT numero2 FROM (SELECT rownum AS numero2, structure.*, rang FROM g_structures structure START WITH structure.id_structure_pere = 0 CONNECT BY structure.id_structure_pere = PRIOR structure.id_structure ORDER SIBLINGS BY structure.rang) WHERE ID_STRUCTURE = 159138) AND numero <= ( SELECT numero2 FROM (SELECT rownum AS numero2, structure.*, rang FROM g_structures structure START WITH structure.id_structure_pere = 0 CONNECT BY structure.id_structure_pere = PRIOR structure.id_structure ORDER SIBLINGS BY structure.rang) WHERE ID_STRUCTURE = 159140)) structures WHERE rec.ID_STRUCTURE = structures.ID_STRUCTURE
3 fois et vu que c'est un traitement pour un arbre, c'est plutôt long d'où ma question.Code:
1
2
3
4 SELECT rownum AS numero2, structure.*, rang FROM g_structures structure START WITH structure.id_structure_pere = 0 CONNECT BY structure.id_structure_pere = PRIOR structure.id_structure ORDER SIBLINGS BY structure.rang
Merci d'avance !