mysql - 选择每年的平均价格
问题描述
我有一个这样的数据集:
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
谢谢你。
解决方案
你可以试试这样的
select [year] as y, avg(average_price) as avg_price
from Ttable
group by [year];
推荐阅读
- laravel - Laravel - 从表单生成 PDF,还包括用户的签名
- graphql - GraphiQL - 上传文件
- regex - Python - 每次在字符串中找到模式时如何添加新行?
- c++ - 初始化 C 数组的引用成员不要在 Visual Studio 2015 上编译
- kubernetes - 为数据科学/机器学习任务设置多用户作业调度程序
- javascript - JavaScript 只允许用户点击一次
- awk - 从前 N 个字符中获取唯一值
- ruby-on-rails - Rails 每当 rake 中止!PG::ConnectionBad: fe_sendauth: 未提供密码
- c++ - 不将函数的返回值分配给变量的含义
- .net-core - Dot net core web API url 尝试通过 ajax 调用使用互联网