【问题标题】:Select average price of per year [closed]选择每年的平均价格[关闭]
【发布时间】: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


【解决方案1】:

你可以试试这样的

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-22
    相关资源
    最近更新 更多