假设您有以下表格:
TABLE Car
car_id
num
TABLE Car_description
dsc_id
car_id
model
TABLE Result
res_id
car_id
race_num
result
任务是为我们拥有超过 2 辆汽车和 Car.num、Car_description.model 的比赛选择最高、平均分数以获得最佳汽车。我写了以下查询
SELECT
race_num,
MAX(result),
AVG(result),
STDDEV(result)
FROM Result r, Car c, Car_description d
WHERE c.car_id = r.car_id AND d.car_id = c.car_id
HAVING COUNT(result) > 2
GROUP BY r.race_num
但我不明白 - 如何为每场比赛选择最好的车号和型号?谢谢。