MySQL - 在Group by上使用desc

时间:2016-12-19 01:37:13

标签: mysql

我有这个查询,我想在avg上使用desc命令:

select Nomcircuit, avg(Monuments.NBETOILE) as TotalEtoiles from Circuits      
inner join CircuitsMonuments on Circuits.Idcircuit = CircuitsMonuments.Idcircuit
inner join Monuments on Monuments.Idmonument = CircuitsMonuments.Idmonument
group by Nomcircuit;

我尝试了几件事,但它似乎没有效果。

1 个答案:

答案 0 :(得分:1)

按照你的建议做:

SELECT Nomcircuit,
       AVG(Monuments.NBETOILE) AS TotalEtoiles
FROM Circuits      
INNER JOIN CircuitsMonuments
    ON Circuits.Idcircuit = CircuitsMonuments.Idcircuit
INNER JOIN Monuments
    ON Monuments.Idmonument = CircuitsMonuments.Idmonument
GROUP BY Nomcircuit
ORDER BY TotalEtoiles DESC