查询将转换按另一个属性分组的升序平均值

时间:2015-01-12 17:44:43

标签: mysql sql group-by average

我有3个表:accidentinvolvecar

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  

0 个答案:

没有答案