我有 4 张桌子。我试图为每个汽车品牌获得最大价值。有10个品牌。我试图找出每个品牌最贵的车。
我做的第一件事是将所有我想从中获取信息的表格分组。我已经加入了 BRAND、MODEL、CLASS 和 VEH 表。但是,我不确定如何获得每个组的最大值。
SELECT B.BRAND_NAME, M.MODEL_NAME, C.CLASS_NAME, V.VEH_YEAR, V.VEH_PRICE
FROM ((VEHICLE V INNER JOIN CLASS C ON V.CLASS_ID = C.CLASS_ID)
INNER JOIN MODEL M ON M.MODEL_ID = V.MODEL_ID)
INNER JOIN BRAND B ON B.BRAND_ID = M.BRAND_ID
我试过:
SELECT B.BRAND_NAME, M.MODEL_NAME, C.CLASS_NAME, V.VEH_YEAR, V.VEH_PRICE
FROM (
SELECT B.BRAND_NAME, MAX(V.VEH_PRICE)
FROM ((VEHICLE V INNER JOIN CLASS C ON V.CLASS_ID = C.CLASS_ID)
INNER JOIN MODEL M ON M.MODEL_ID = V.MODEL_ID)
INNER JOIN BRAND B ON B.BRAND_ID = M.BRAND_ID
GROUP BY B.BRAND_NAME
);
我越来越: