首页 > 解决方案 > 选择每年的平均价格

问题描述

我有一个这样的数据集:

year, average_price
1993, 222.2220,
1993, 2333.333
1993, 333.345
1994, 3445.444
1994, 4493.33
1995, 66005.33
1995, 33994.333
1995, 33993.333,
1996, 33884.33

我需要在这个数据集中显示每年的平均价格。

这是否意味着我可以计算 average_prices 的总和,然后逐年进行分组,像这样?

select year as y, sum(average_price) as avg_price from table group by y

谢谢你。

标签: mysqlsqldatasetaggregategrouping

解决方案


你可以试试这样的

select [year] as y, avg(average_price) as avg_price 
from Ttable 
group by [year];

推荐阅读