首页 \ 问答 \ MySQL查询获取每个月数据的平均值数组(MySQL query to get array of averages of each month's data)

MySQL查询获取每个月数据的平均值数组(MySQL query to get array of averages of each month's data)

我有一张名为historical_currencies_rate的表格,其中我保存了一些已知货币的最近8年货币汇率。 例如(欧元兑美元)。 表看起来像这样

+---------------------------+---------------+------------+
|       rate_date           | currency_pair |    rate    |
+---------------------------+---------------+------------+
|       2006-01-01          |    EUR-USD    |  1.1797    |
|       2006-02-01          |    EUR-USD    |  1.1826    |
|       2006-03-01          |    EUR-USD    |  1.1875    |
|       2006-04-01          |    EUR-USD    |  1.2083    |
|       2006-05-01          |    EUR-USD    |  1.2088    |
|       2006-06-01          |    EUR-USD    |  1.2093    |
|       2006-07-01          |    EUR-USD    |  1.2093    |
|       2006-08-01          |    EUR-USD    |  1.2093    |
|       2006-01-01          |    JPY-USD    |  0.01275   |
|       2006-02-01          |    JPY-USD    |  0.01275   |
|       2006-03-01          |    JPY-USD    |  0.01275   |
|       2006-04-01          |    JPY-USD    |  0.01275   |
|       2006-05-01          |    JPY-USD    |  0.01275   |
|       2006-06-01          |    JPY-USD    |  0.01275   |
|       2006-07-01          |    JPY-USD    |  0.01275   |
|       2006-08-01          |    JPY-USD    |  0.01275   |
|       2006-01-01          |    GBP-USD    |  1.559     |
|       2006-02-01          |    GBP-USD    |  1.559     |
|       2006-03-01          |    GBP-USD    |  1.559     |
|       2006-04-01          |    GBP-USD    |  1.559     |
|       2006-05-01          |    GBP-USD    |  1.559     |
|       2006-06-01          |    GBP-USD    |  1.559     |
|       2006-07-01          |    GBP-USD    |  1.559     |
|       2006-08-01          |    GBP-USD    |  1.559     |
|       2006-01-01          |    AUD-USD    |  1.0515    |
|       2006-02-01          |    AUD-USD    |  1.0515    |
|       2006-03-01          |    AUD-USD    |  1.0515    |
|       2006-04-01          |    AUD-USD    |  1.0515    |
|       2006-05-01          |    AUD-USD    |  1.0515    |
|       2006-06-01          |    AUD-USD    |  1.0515    |
|       2006-07-01          |    AUD-USD    |  1.0515    |
|       2006-08-01          |    AUD-USD    |  1.0515    |
|       2006-01-02          |    EUR-USD    |  1.2092    |
|       2006-02-02          |    EUR-USD    |  1.2066    |
|       2006-03-02          |    EUR-USD    |  1.2061    |
|       2006-04-02          |    EUR-USD    |  1.2061    |
|       2006-05-02          |    EUR-USD    |  1.2061    |
|       2006-06-02          |    EUR-USD    |  1.1981    |
|       2006-07-02          |    EUR-USD    |  1.1973    |
|       2006-08-02          |    EUR-USD    |  1.1948    |
+---------------------------+---- ----------+------------+

在这里,我向您展示了8天和2006年的几种货币的数据,但我拥有18种货币的大量数据,截至2013年的数据为30天。

我的查询是,我想要一个包含每月特定货币的平均货币汇率的数组。 例如, January月份我的例子中的平均EUR-USD JPY-USD1.19935JPY-USD0.01275GBP-USDJanuary 1.19935February月份的平均EUR-USD GBP-USD1.2030375等。

我想要每个月的平均数EUR-USD或者可能是其他一些货币对,即。 应该是这样的

`[1.19935, 1.2030375, ......]`

query-result = [avg。 January, 2006EUR-USD平均值。 February, 2006EUR-USD ,.............,平均 January, 2013EUR-USD汇率,等等,最长可达8年。

请帮我写一个查询。谢谢


I have a table named historical_currencies_rate where I have saved last 8 years currency rate of some known currencies. eg (EUR-USD). Table looks like this

+---------------------------+---------------+------------+
|       rate_date           | currency_pair |    rate    |
+---------------------------+---------------+------------+
|       2006-01-01          |    EUR-USD    |  1.1797    |
|       2006-02-01          |    EUR-USD    |  1.1826    |
|       2006-03-01          |    EUR-USD    |  1.1875    |
|       2006-04-01          |    EUR-USD    |  1.2083    |
|       2006-05-01          |    EUR-USD    |  1.2088    |
|       2006-06-01          |    EUR-USD    |  1.2093    |
|       2006-07-01          |    EUR-USD    |  1.2093    |
|       2006-08-01          |    EUR-USD    |  1.2093    |
|       2006-01-01          |    JPY-USD    |  0.01275   |
|       2006-02-01          |    JPY-USD    |  0.01275   |
|       2006-03-01          |    JPY-USD    |  0.01275   |
|       2006-04-01          |    JPY-USD    |  0.01275   |
|       2006-05-01          |    JPY-USD    |  0.01275   |
|       2006-06-01          |    JPY-USD    |  0.01275   |
|       2006-07-01          |    JPY-USD    |  0.01275   |
|       2006-08-01          |    JPY-USD    |  0.01275   |
|       2006-01-01          |    GBP-USD    |  1.559     |
|       2006-02-01          |    GBP-USD    |  1.559     |
|       2006-03-01          |    GBP-USD    |  1.559     |
|       2006-04-01          |    GBP-USD    |  1.559     |
|       2006-05-01          |    GBP-USD    |  1.559     |
|       2006-06-01          |    GBP-USD    |  1.559     |
|       2006-07-01          |    GBP-USD    |  1.559     |
|       2006-08-01          |    GBP-USD    |  1.559     |
|       2006-01-01          |    AUD-USD    |  1.0515    |
|       2006-02-01          |    AUD-USD    |  1.0515    |
|       2006-03-01          |    AUD-USD    |  1.0515    |
|       2006-04-01          |    AUD-USD    |  1.0515    |
|       2006-05-01          |    AUD-USD    |  1.0515    |
|       2006-06-01          |    AUD-USD    |  1.0515    |
|       2006-07-01          |    AUD-USD    |  1.0515    |
|       2006-08-01          |    AUD-USD    |  1.0515    |
|       2006-01-02          |    EUR-USD    |  1.2092    |
|       2006-02-02          |    EUR-USD    |  1.2066    |
|       2006-03-02          |    EUR-USD    |  1.2061    |
|       2006-04-02          |    EUR-USD    |  1.2061    |
|       2006-05-02          |    EUR-USD    |  1.2061    |
|       2006-06-02          |    EUR-USD    |  1.1981    |
|       2006-07-02          |    EUR-USD    |  1.1973    |
|       2006-08-02          |    EUR-USD    |  1.1948    |
+---------------------------+---- ----------+------------+

here I have shown you tha data of few currency upto 8 days and for year 2006 but i have a huge data of 18 currencies with 30 days data upto 2013.

My query is that I want an array which contains the avg currency rate of a particular currency on monthly basis. for eg avg of EUR-USD in my example for the month of January is 1.19935, JPY-USD is 0.01275, GBP-USD is 1.559 and avg of EUR-USD for the month of February is 1.2030375 etc.

I want array of averages of EUR-USD or may be some other currency pair, of each month ie. it should be like

`[1.19935, 1.2030375, ......]`

query-result = [avg. of EUR-USD for January, 2006 , avg. of EUR-USD for February, 2006, ............., avg. of EUR-USD for January, 2013, ..... ] and so on up to 8 years.

Please help me in writing this in single query.Thanks


原文:
更新时间:2022-04-10 13:04

最满意答案

你说你在src文件夹中执行了import src.features.featureExtraction 。 只有当您位于父级MyProject文件夹中时,该导入才有意义。

在pycharm首选项中,搜索Project Structure并注意它正在使用的内容根目录(MyProject)。 这解释了您从IDE和命令行看到的不同行为。


You said you executed import src.features.featureExtraction while in the src folder. That import makes sense only while you are in the parent MyProject folder.

In pycharm prefs, search for Project Structure and notice the content root (MyProject) that it is using. That explains the different behavior you saw from IDE and from command line.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。