【发布时间】:2021-05-08 01:20:08
【问题描述】:
我有一个这样的数据集:
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
谢谢。
【问题讨论】:
-
提示:如果您想要平均价格,请使用
AVG()。 -
这能回答你的问题吗? SQL query with avg and group by
-
@GordonLinoff average_price 列是该条目的实际平均价格值,我只需要显示每年的所有平均价格。我是否需要当年所有平均价格的总和,而不是按年份分组。我希望这对你来说很清楚,谢谢。
标签: mysql sql dataset aggregate grouping