我有3个表:accident
,involve
和car
。
Car (registration_nr, model,year) involve (licence_nr,registration_nr (FK of car), damages , raport_nr (FK of accident)) accident(raport_nr, date)
我必须找到损失的平均值,但必须是group by m.model
。我可以找到平均值,但我不能按模型按升序平均分组。
SELECT
AVG(damage),c.model
FROM
involve AS i
JOIN
car AS c ON i.registration_nr = c.registration_nr
JOIN
accident AS a ON i.raport_nr = a.raport_nr
GROUP BY m.model