j'ai une table Ventes (Categorie, article, prix)
renvoie le prix max par catégorie.Code:
1
2
3
4 select categorie, max(prix) from VENTES group by categorie
comment obtenir l'article correspondant au prix max?
merci
Version imprimable
j'ai une table Ventes (Categorie, article, prix)
renvoie le prix max par catégorie.Code:
1
2
3
4 select categorie, max(prix) from VENTES group by categorie
comment obtenir l'article correspondant au prix max?
merci
Faire une jointure :
Autre solution avec SQL Server 2005 et les fonctions de fenêtrage :Code:
1
2
3
4
5
6
7 SELECT * FROM Ventes AS V INNER JOIN (SELECT categorie, max(prix) AS P FROM VENTES GROUP BY categorie) AS M ON V.categorie = M.categorie AND V.prix = M.P
A +Code:
1
2
3
4
5
6
7 SELECT * FROM ( SELECT V.*, MAX(prix) OVER(PARTITION BY categorie) AS MAXPRIX FROM Ventes ) AS T WHERE prix = MAXPRIX