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-USD
是1.19935
,JPY-USD
是0.01275
,GBP-USD
是January
1.19935
,February
月份的平均EUR-USD
GBP-USD
是1.2030375
等。我想要每个月的平均数
EUR-USD
或者可能是其他一些货币对,即。 应该是这样的`[1.19935, 1.2030375, ......]`
query-result = [avg。
January, 2006
的EUR-USD
平均值。February, 2006
的EUR-USD
,.............,平均January, 2013
的EUR-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 ofJanuary
is1.19935
,JPY-USD
is0.01275
,GBP-USD
is1.559
and avg ofEUR-USD
for the month ofFebruary
is1.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
forJanuary, 2006
, avg. ofEUR-USD
forFebruary, 2006
, ............., avg. ofEUR-USD
forJanuary, 2013
, ..... ] and so on up to 8 years.Please help me in writing this in single query.Thanks
原文:
最满意答案
你说你在
src
文件夹中执行了import src.features.featureExtraction
。 只有当您位于父级MyProject
文件夹中时,该导入才有意义。在pycharm首选项中,搜索Project Structure并注意它正在使用的内容根目录(MyProject)。 这解释了您从IDE和命令行看到的不同行为。
You said you executed
import src.features.featureExtraction
while in thesrc
folder. That import makes sense only while you are in the parentMyProject
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.
相关问答
更多-
我不认为你的问题与python有什么关系,考虑到python脚本做你想要的。 问题是让环境变量起作用,对吧? 我相信这个问题有你想要的答案: 如何在Windows命令提示符下创建ls? 简而言之,在我看来,实现您想要的方法是不使用环境变量,而是创建批处理文件。 I don't think your problem has anything to do with python, considering that the python script does what you want. The problem ...
-
import os os.system("C:\path_to_python\python.exe C:\path_to_file\file.py") os.system()返回命令的退出值,所以如果你需要脚本的一些输出,这将不起作用。 import os os.system("C:\path_to_python\python.exe C:\path_to_file\file.py") os.system() returns the command's exit value so if you need ...
-
urllib.request是用Python 3引入的。很有可能当你从命令行运行代码时,你使用的是较旧的Python 2.x二进制文件。 在命令行上键入python --version以查看正在使用的Python。 编辑以回应Drewdin的评论 运行Mac OS X的Python 3.1.2安装程序,我看到: 注意:默认情况下,此程序包不会更新您的shell配置文件,也不会在/ usr / local中安装文件。 双击任何时候更新Shell配置文件以使3.1.2成为默认Python。 安装程序将应用程序放 ...
-
从这本书(第44页,第4版): 最后,如果脚本位于与您工作的目录不同的目录中,请记住提供脚本的完整路径。 对于您的情况,这意味着使用 C:\User\Example> python C:\User\Example\my_scripts\script1.py 您可以编写一个批处理文件,在预定义的目录中查找该脚本: @echo off setlocal PATH=C:\User\Example\Python36;%PATH% SCRIPT_DIR=C:\User\Example\my_scripts pyth ...
-
使用命令行运行python脚本有什么好处?(What is the advantage of running python script using command line?)[2022-06-22]
人们为不同的目的使用不同的工具。 关于任何程序的界面的一个重要问题是谁是用户? 作为程序员,您将使用解释器来测试程序并检查错误。 通常,用户并不真正需要访问内部变量,因为他们没有使用解释器与应用程序/脚本交互。 例如,对于Python Web应用程序,通常会有一个main.py脚本将客户端HTTP请求重定向到适当的处理程序。 这些处理程序在客户端请求时自动执行python脚本。 然后将该输出显示给用户。 在Python Web应用程序中,除非您是开发人员试图消除程序中的错误,否则通常不关心访问像main.p ... -
你可能已经有了R,因为你已经可以运行你的脚本了。 你所要做的就是找到它的二进制文件(Rscript.exe文件)。 然后打开Windows命令行([cmd] + [R]>输入:“cmd”> [enter]) 输入R.exe的完整路径,然后输入脚本的完整路径。 You probably already have R, since you can already run your script. All you have to do is find its binaries (the Rscript.exe f ...
-
如果您要从Python脚本运行该命令,那么您希望查看带有stdout参数的subprocess stdout 。 如果您要从单独的shell脚本运行该脚本和Python脚本,那么您希望从一个脚本管道到另一个脚本管道,然后从sys.stdin读取。 If you're going to run the command from your Python script then you want to look at subprocess with its stdout arguments. If you're ...
-
是的,这是可能的(如果我理解正确的话。问题有点不清楚) 您需要做的第一件事是在脚本的顶部添加一个shebang: https ://en.wikipedia.org/wiki/Shebang_(Unix ) 。 我看到你提到了cmd.exe所以我假设你需要这个在Windows上运行吗? 在这种情况下,你应该阅读https://docs.python.org/3/using/windows.html#shebang-lines 在unix主机上,我们需要做的第二件事是使用chmod +x
... -
“独立的Django脚本” "Standalone Django scripts"
-
你说你在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 ...