以下是我可以拥有的数据的例子
**Car Name Brand Name**
Megan Renault
Clio Renault
Clio Renault
Willys Jeep
Willys Jeep
Willys Jeep
下面的SQL会给我一个结果显示
Brand Name Car
JEEP Willys
我想拥有每一个品牌名称和最好的租车。不是最好的。
会喜欢任何帮助。顺便说一句,我不知道如何使用内部关节,所以如果解决方案可以使用where
条款,那就太棒了! (使用Access)
(想要的结果)
Brand Name Car
JEEP Willys
RENAULT Clio
-
SELECT MARQUE.NOMMA AS [BRAND NAME], VEHICULE.MODELE AS [CAR NAME]
FROM VEHICULE, MARQUE, LOUER
WHERE MARQUE.CODEMA = VEHICULE.CODEMA
AND VEHICULE.NOIMMAT = LOUER.NOIMMAT
GROUP BY MARQUE.NOMMA, VEHICULE.MODELE, MARQUE.CODEMA
HAVING COUNT(MARQUE.NOMMA) = ( SELECT max (NUMBER_OF_LOCATION)
FROM (
SELECT COUNT(MARQUE.NOMMA) as [NUMBER_OF_LOCATION]
FROM VEHICULE, MARQUE, LOUER
WHERE MARQUE.CODEMA = VEHICULE.CODEMA
AND VEHICULE.NOIMMAT = LOUER.NOIMMAT
GROUP BY MARQUE.NOMMA, VEHICULE.MODELE
));
这是方案
Vehicule(NoImmat, Modèle, DateAchat, CodeG#, CodeMA#)
Louer(CodeC#, NoImmat#, DateDebLoc, DateFinLoc, KmDeb, KmFin
Marque(CodeMA, NomMA, PaysMA, DateCreationMA, CodeTYCO#)
答案 0 :(得分:0)
我在您的数据上运行以下内容并获得了所需的结果:
select car, brand
from (select distinct car, brand, count(*) as cnt
from test
group by car)
group by brand
having cnt = max(cnt)