16.20 - MovingAverage例6: 加重移動平均 - Teradata Vantage NewSQL Engine

Teradata Vantage™ - NewSQL Engineの分析関数

prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
プログラミング リファレンス
featnum
B035-1206-162K-JPN

次の使用例は、株価の加重移動平均を計算します。

SQL呼び出し

SELECT * FROM MovingAverage (
  ON company1_stock PARTITION BY name ORDER BY period
  USING
  MAvgType ('W')
  TargetColumns ('stockprice')
  WindowSize (10)
  IncludeFirst ('true')
) AS dt ORDER BY id;

出力

id Name PERIOD stockprice stockprice_wmavg
1 Company1 1961-05-17 00:00:00.000000 460.000000000000  
2 Company1 1961-05-18 00:00:00.000000 457.000000000000  
3 Company1 1961-05-19 00:00:00.000000 452.000000000000  
4 Company1 1961-05-22 00:00:00.000000 459.000000000000  
5 Company1 1961-05-23 00:00:00.000000 462.000000000000  
6 Company1 1961-05-24 00:00:00.000000 459.000000000000  
7 Company1 1961-05-25 00:00:00.000000 463.000000000000  
8 Company1 1961-05-26 00:00:00.000000 479.000000000000  
9 Company1 1961-05-29 00:00:00.000000 493.000000000000  
10 Company1 1961-05-31 00:00:00.000000 490.000000000000 473.454545454545
11 Company1 1961-06-01 00:00:00.000000 492.000000000000 477.927272727273
12 Company1 1961-06-02 00:00:00.000000 498.000000000000 482.909090909091
13 Company1 1961-06-05 00:00:00.000000 499.000000000000 487.327272727273
14 Company1 1961-06-06 00:00:00.000000 497.000000000000 490.527272727273
15 Company1 1961-06-07 00:00:00.000000 496.000000000000 492.854545454545
16 Company1 1961-06-08 00:00:00.000000 490.000000000000 493.472727272727
17 Company1 1961-06-09 00:00:00.000000 489.000000000000 493.345454545455
18 Company1 1961-06-12 00:00:00.000000 478.000000000000 490.745454545455
19 Company1 1961-06-13 00:00:00.000000 487.000000000000 489.800000000000
20 Company1 1961-06-14 00:00:00.000000 491.000000000000 489.690909090909
21 Company1 1961-06-15 00:00:00.000000 487.000000000000 488.836363636364
22 Company1 1961-06-16 00:00:00.000000 482.000000000000 487.163636363636
23 Company1 1961-06-19 00:00:00.000000 479.000000000000 485.236363636364
24 Company1 1961-06-20 00:00:00.000000 478.000000000000 483.490909090909
25 Company1 1961-06-21 00:00:00.000000 479.000000000000 482.272727272727