Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL平均价格_Sql_Inner Join_Average_Aggregate Functions - Fatal编程技术网

SQL平均价格

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 |

我需要一个SQL查询,将显示制造商的名称和平均价格。谢谢

表1产品

+----+---------+-------+--------------+
| 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