2012-12-12 26 views
2

我有一個類似的MySQL表:如何使用MYSQL查詢檢索元素的不同組合的平均值?

Fruit |Color |Brand |Rating 
------------------------------- 
Apple Red  b1  5.4 
Banana Yellow b2  1.1 
Apple Red  b1  2.2 
Apple Green b3  4.1 
Apple Green b2  1.9 
Apple Red  b1  3.7 

這是檢索的平均得分爲每個不同的項目正確的查詢?即如何獲得「Apple Red b1」組合的平均評分?

非常感謝您的幫助。

回答

0

這應該工作你的情況:

SELECT AVG(Rating) FROM table GROUP BY Fruit, Color, Brand;