回复:根据特定日期获取数据 [英] Re:Getting data based on particular dates
问题描述
亲爱的编码员,
我有以下疑问:
我想要以最近3天,10天等股票平均价格计算。有成千上万的股票。
日期不在订单即周一至周五,因为周六市场未开盘。星期天,但有时候市场日之间会有假期,也就是说星期三是假日。周六市场也开放。
这是日期的数据:
Tradedate:
2012 -12-17
2012-12-14
2012-12-13
2012-12-12
2012-12-11
2012-12-10
2012-12-07
2012-12-06
2012-12-05
2012-12-04
2012-12-03
2012- 11-30
2012-11-29
2012-11-27
2012-11-26
2012-11-23
2012-11-22
2012-11-21
2012-11-20
2012-11-19
2012-11-16
这些是交易日期&每个交易者都有数以千计的股票名称及其价格和价格。交易量。
我想采取过去三个交易日的平均交易量但是当我尝试这样做时会丢失一些东西,所以要求所有人帮助我。
这里我想要最后3个交易日的平均交易量。这里提到的日期是降序排列。 />
希望我会得到一些查询来做到这一点。
谢谢&问候。
HI,
要获得最后N个交易日期,您可以查看以下链接。
sql查询以获得最后N个交易日
这可能会告诉您正确的方式。
谢谢
这是它的sql。
选择 pricesymbol,avg(volume) as averagevolume,avg (价格) as averageprice 来自 YOURTABLE group by pricesymbol;
亲爱的所有人,
感谢特别是来自Armando Talex的回复。我测试了他建议的解决方案;它工作正常。
但是我找到了自己的解决方案来解决这个问题如下:
- 首先放下桌子。由于我已经创建了一个程序来进行这个计算,我正在丢弃用于临时目的的表格
drop table #date
- 以下查询将给出我在数据库中的前8个交易日期&这些日期将存储在临时表中#date
通过TradeDate订单选择前8名来自EODNSE集团的#date交易日期
- 以下查询将给出结束日期即第8个交易日期
从交易日#date订单中选择前1交易
以下是完成查询:
drop table #date
选择 top 8 tradedate into #date from EODNSE group by TradeDate order by TradeDate desc
声明 @ StartDate 日期 - @Startdate是今天的当前日期
声明 @ Enddate date - @ Enddate是当前日期减去2天的返回日期
set @ StartDate =(选择 top 1 TradeDate 来自 EODNSE 订单 按 TradeDate desc )< span class =code-comment> - 这将获得当前日期
set @ Endda te =(选择 top 1 tradedate 来自 #date 订单 by tradedate) - 这将是#date临时表的最后日期
Dear Coders,
I have a following query:
I want to take Stock price avg for last 3 days,10 days etc.There are thousand of stocks.
The dates are not in order i.e. Monday to Friday only as market not open on saturday & Sunday but sometime there is a holiday in between market days i.e. can say Wednesday is a holiday.Sometime market open on Saturday also.
This is the data for dates:
Tradedate:
2012-12-17
2012-12-14
2012-12-13
2012-12-12
2012-12-11
2012-12-10
2012-12-07
2012-12-06
2012-12-05
2012-12-04
2012-12-03
2012-11-30
2012-11-29
2012-11-27
2012-11-26
2012-11-23
2012-11-22
2012-11-21
2012-11-20
2012-11-19
2012-11-16
These are the trade date & each tradedate has thousands of stock names along with their price & traded volumes.
I want to take avg volumes of last three trading days but something is missing when i tried that so requesting all of you to help me.
here i want the avg volumes for last 3 trade date.The dates mentioned here are in descending order.
Hope i will get some query to do this.
Thanks & Regards.
HI,
For getting the last N number of trading date you can view the following link.
sql query to get the last N trading days
This may show you the right way.
Thanks
Here is the sql for it.
select pricesymbol,avg(volume) as averagevolume,avg(price) as averageprice from YOURTABLE group by pricesymbol;
Dear All,
Thanks For the response especially from Armando Talex. I tested the solution suggested by him; it''s working fine.
But i found my own solution to solve this as follows:
--First drop the table.As i have created a procedure to do this calculation i am droping the table which is crated for temp purpose
drop table #date
--The below query will give me top 8 trading dates which are in the database & these dates will get store in a temp table #date
select top 8 tradedate into #date from EODNSE group by TradeDate order by TradeDate desc
--The below query will give me the enddate i.e. 8th trade date
select top 1 tradedate from #date order by tradedate
Following is the full queries to do this:
drop table #date select top 8 tradedate into #date from EODNSE group by TradeDate order by TradeDate desc declare @StartDate date --@Startdate is the current date of today declare @Enddate date --@Enddate is the current date less 2 day's back date set @StartDate = (select top 1 TradeDate from EODNSE order by TradeDate desc) --This will get the current date set @Enddate = (select top 1 tradedate from #date order by tradedate)--This will take the last date from #date temp table
这篇关于回复:根据特定日期获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!