Bonjour à tous,
Je souhaite obtenir le résultat suivant :
Nom | Nb Contrat 1 | Nb Contrat 2
Nom1 | 3 | 5
Nom2 | 5 | 10
J'ai 2 tables :
- Table de personnnes avec les champs [IdPers, Nom]
- Table des Contrats avec les champs [IdContrat, Ref, Type, IdPers]
Ma requête est la suivante :
Le problème est que j'obtiens cela :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 SELECT Pers.Nom, case when Cntr.Type =0 then count(Cntr.Ref) end as NB_Contrat_1, case when Cntr.Type =1 then count(Cntr.Ref) end as NB_Contrat_2 FROM Personne Pers INNER JOIN Contrat Cntr ON Pers.IdPers = Cntr.IdPers WHERE Cntr.Ref Like 'P%' group by Pers.Nom, Cntr.Type
Nom | Nb Contrat 1 | Nb Contrat 2
Nom1 | 3 | NULL
Nom1 | NULL | 5
Nom2 | 5 | NULL
Nom2 | NULL | 10
Merci d'avance pour votre aide![]()
Partager