Organiser par maximum une table contenant COUNT avec MAX

Résolu/Fermé
kabrice01 Messages postés 1180 Date d'inscription dimanche 21 décembre 2008 Statut Membre Dernière intervention 12 avril 2021 - Modifié par kabrice01 le 5/10/2015 à 11:32
kabrice01 Messages postés 1180 Date d'inscription dimanche 21 décembre 2008 Statut Membre Dernière intervention 12 avril 2021 - 6 oct. 2015 à 06:54
Bonjour, j'ai la base suivante :
FONCTION (Numfonct, libfonct, salaire)
SERVICE (Numserv,libserv)
EMPLOYE (Numemp, nom, prenom,numfonct,numserv)

Je voudrai afficher pour chaque service, la fonction dont le nombre d'employés l'occupant est le plus grand.
Voici ma démarche :
J'ai la requête suivante :
SELECT libserv,libfonct, COUNT(numemp) 
FROM EMPLOYE INNER JOIN SERVICE ON EMPLOYE.NUMSERV=SERVICE.NUMSERV INNER JOIN FONCTION ON EMPLOYE.NUMFONCT=FONCTION.NUMFONCT
GROUP BY libserv, libfonct
ORDER BY libserv;
qui me donne les services, les fonctions ainsi que leur nombre d'employé respectif. Mais je voudrai pouvoir organiser ces données pour n'avoir que le maximum des de chaque service, mais je ne sais pas comment faire ?!
Je vous remerci de m'aider





pense à ta vie et pense à l'eternité
A voir également:

1 réponse

DelNC Messages postés 2234 Date d'inscription samedi 25 octobre 2014 Statut Membre Dernière intervention 22 février 2020 1 999
Modifié par DelNC le 5/10/2015 à 11:47
Bonjour,

je ne suis pas certaine que çà marche mais essayez ceci

SELECT libserv,libfonct, COUNT(numemp)
FROM EMPLOYE INNER JOIN SERVICE ON EMPLOYE.NUMSERV=SERVICE.NUMSERV INNER JOIN FONCTION ON EMPLOYE.NUMFONCT=FONCTION.NUMFONCT
GROUP BY libserv, libfonct,
order by count(*) desc limit 1
0
kabrice01 Messages postés 1180 Date d'inscription dimanche 21 décembre 2008 Statut Membre Dernière intervention 12 avril 2021 28
5 oct. 2015 à 12:48
Désolé ça ne marche pas ;(. En plus Oracle ne prend pas en charge "limit"
0
kabrice01 Messages postés 1180 Date d'inscription dimanche 21 décembre 2008 Statut Membre Dernière intervention 12 avril 2021 28
6 oct. 2015 à 06:54
ça y est, j'ai trouvé la solution, c'est :
select libfonct,libserv,count(numemp) 
from ((employe natural join service s1) natural join fonction f1)
group by libserv,libfonct
having count(numemp)=(select max(count(numemp)) from ((employe natural join service) natural join fonction)
where libfonct=f1.libfonct group by libserv,libfonct);


Et ça fonctionnent nickelement
0