这是我能做的吗?我想尝试将两个时间序列进行交叉关联。
我认为窗口函数应该这样做,但不能100%确定如何在SQL中构造它。
答案 0 :(得分:1)
就像一个玩的想法(更适合评论但更容易出现在答案中):
SELECT
CORR(a, b) AS correlation,
CORR(a, b1) AS cross_correlation_lag_1,
CORR(a, b2) AS cross_correlation_lag_2,
CORR(a, b3) AS cross_correlation_lag_3,
CORR(a, b4) AS cross_correlation_lag_4,
CORR(a, b5) AS cross_correlation_lag_5
FROM (
SELECT
a.ts AS ts,
a.val AS a,
b.val AS b,
LEAD(b.val, 1) OVER(ORDER BY b.ts) AS b1,
LEAD(b.val, 2) OVER(ORDER BY b.ts) AS b2,
LEAD(b.val, 3) OVER(ORDER BY b.ts) AS b3,
LEAD(b.val, 4) OVER(ORDER BY b.ts) AS b4,
LEAD(b.val, 5) OVER(ORDER BY b.ts) AS b5
FROM time_series1 AS a
JOIN time_series2 AS b
ON a.ts = b.ts
)