close

TABLE  :  放股票歷史價位 , 但是沒有3,6,18,30,72日均價

=_=|||,,,,

因為....我抓的地方就不提供   囧T2

OK!那我要算當天的三日均價怎樣算

抓top 3 筆的資料的收盤/3   ??

當天的ok!

那昨天的三日均價呢....XD..

不要也用top 3 呀  

我的table是全部的股票  所有日期的當天的三日均價都沒有...XD...

那昨天的三日均價怎麼算?

不要用TOP 3來算吧 XD

要往前抓,, 抓昨天開始 往前推三天的價位/3

那SQL  怎樣下?

就降子下,重點就在,,排序要反轉兩次 @_@


select idx_Key , StockID,LogTime,DealPrice ,

(    select    avg( cast(DealPrice as money))  ma   from STOCK_PRICE_LOG A where A.StockID=C.StockID and      LogTime<=C.LogTime
and     LogTime  >=

 (select top 1 T.logtime from  ( select  top  3  *  from  STOCK_PRICE_LOG B where StockID=A.StockID  and  B.LogTime<=C.LogTime  order by logtime desc ) as T

 order by T.logtime )      )


as ma3

from  STOCK_PRICE_LOG C  order by StockID, logtime desc

 

把這個COMMAND 設成VIEW  再跑SP   用PK KEY 去對照

更新回去就可以了

6日均價,月均價,均量都可以用這樣去做

其他的均價都依此類推就可以囉

by 十一

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 11 的頭像
    11

    冠霖的部落格

    11 發表在 痞客邦 留言(0) 人氣()