SQL平均价格
我需要一个SQL查询,将显示制造商的名称和平均价格。谢谢 表1产品SQL平均价格,sql,inner-join,average,aggregate-functions,Sql,Inner Join,Average,Aggregate Functions,我需要一个SQL查询,将显示制造商的名称和平均价格。谢谢 表1产品 +----+---------+-------+--------------+ | ID | Product | Price | Manufacturer | +----+---------+-------+--------------+ | 1 | Game1 | 100 | 1 | | 2 | Game2 | 50 | 2 | | 3 | Game4 |
+----+---------+-------+--------------+
| ID | Product | Price | Manufacturer |
+----+---------+-------+--------------+
| 1 | Game1 | 100 | 1 |
| 2 | Game2 | 50 | 2 |
| 3 | Game4 | 70 | 1 |
+----+---------+-------+--------------+
表2制造商
+----+-----------+
| Id | Name |
+----+-----------+
| 1 | Sony |
| 2 | Microsoft |
+----+-----------+
只需加入并聚合:
select m.name, avg(p.price) avg_price
from manufacturer m
inner join products p on p.manufacturer = m.id
group by m.id, m.name