Bonjour,

J'avais effectuer un premier bout de code SQL afin de récupérer :


La liste des noms d'organisation commence par HRE- et comportant juste 1 lettre après le tiret (comme HRE-A et non HRE-AB )

Combien de personnes travaille pour chaque organisation

La somme des personnes qui travaillent dans les différentes organisation

Pour chaque organisation indiquait les catégories qui sont prise ( ex : Manpower Assig., National Space Agency, Permanent, ...)

Voici mon 1er code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
SELECT DISTINCT SUBSTR(WFORGUNIT_CODE, 0, 5), 
COUNT(WFORGUNIT_ID), 
SUM(COUNT(WFORGUNIT_ID)) OVER(),
LISTAGG(DISTINCT WFCAT_DESC, '--')
FROM WFORGUNITS 
INNER JOIN WFPOSITIONS ON WFORGUNITS.ID = WFPOSITIONS.WFORGUNIT_ID
INNER JOIN WFRPERASS ON WFPOSITIONS.ID = WFRPERASS.WFPOSITION_ID 
INNER JOIN WFCATS ON WFPOSITIONS.WFCAT_ID = WFCATS.ID
WHERE SUBSTR(WFORGUNIT_CODE, 0, 4) = 'HRE-' AND WFRPERASS.WFRPERASS_ENDT >= SYSDATE AND WFRPERASS.WFRPERASS_STDT <= SYSDATE
GROUP BY SUBSTR(WFORGUNIT_CODE, 0, 5)
Cela donne :

HRE-C 7 269 Manpower Assig.--National Space Agency--Permanent
HRE-M 37 269 Manpower Assig.--Permanent--Service Contractor
HRE-O 59 269 Consultant--Manpower Assig.--National Space Agency--Permanent--Service Contractor--Young Grad. Trainees
HRE-P 69 269 Int. Research Fellow--Manpower Assig.--Permanent--Service Contractor
HRE-Q 6 269 Permanent
HRE-R 42 269 Manpower Assig.--Permanent--Service Contractor
HRE-S 16 269 Int. Research Fellow--Manpower Assig.--Permanent--Service Contractor
HRE-X 33 269 Manpower Assig.--Permanent--Young Grad. Trainees

Maintenant j'aimerai rajouter une autre colonne qui indique combien il y aurai de personnes dans chaque catégories ( les Manpower Assig., National Space Agency, ... )

J'ai donc repris le même code sql et rajouter 2 lignes (en rouge) :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
SELECT DISTINCT SUBSTR(WFORGUNIT_CODE, 0, 5), 
COUNT(WFORGUNIT_ID), 
SUM(COUNT(WFORGUNIT_ID)) OVER(),
LISTAGG(DISTINCT WFCAT_DESC, '--'),
LISTAGG(COUNT(WFORGUNIT_ID), '--')
FROM WFORGUNITS 
INNER JOIN WFPOSITIONS ON WFORGUNITS.ID = WFPOSITIONS.WFORGUNIT_ID
INNER JOIN WFRPERASS ON WFPOSITIONS.ID = WFRPERASS.WFPOSITION_ID 
INNER JOIN WFCATS ON WFPOSITIONS.WFCAT_ID = WFCATS.ID
WHERE SUBSTR(WFORGUNIT_CODE, 0, 4) = 'HRE-' AND WFRPERASS.WFRPERASS_ENDT >= SYSDATE AND WFRPERASS.WFRPERASS_STDT <= SYSDATE
GROUP BY SUBSTR(WFORGUNIT_CODE, 0, 5), LISTAGG(DISTINCT WFCAT_DESC, '--')
L'erreur que cela génère : SQL Error [934] [42000]: ORA-00934: fonction de groupe non autorisée ici

En me renseignant un peu j'ai penser que je devais utiliser un HAVING mais cela me procure une autre erreur : SQL Error [920] [42000]: ORA-00920: opérateur relationnel non valide

En espérant avoir été plus ou moins clair, j'aurais aimer savoir si quelqu'un aurait une piste de réflexion ou quelque chose comme


Merci Bien