2015年8月28日 星期五

SQL-20日平均量

select A.StockNo , A.Date , (
select round(avg(cast(B.xVolume as float)),2)  from
(select top 20 cast(C.xVolume as float) xVolume from StockDailyHis C
  where C.Date<=A.Date and C.StockNo = A.StockNo order by C.Date desc) B
) Volume_20MA from StockDailyHis A where
1=1 and A.Date >= '20140101'
group by A.StockNo, A.Date
order by A.StockNo , A.Date

沒有留言:

張貼留言