如何使用postgresql计算不同组之间的相关性
HOw to calculate correlation between different groups using postgresql
我在 SQL 中有一个表,我想根据 Norms 列计算 id=1 和 id=2 之间的相关系数 corr()。有什么提示吗?和 2) 我怎样才能找到 id=1 和 id=2 在重叠日期的“标准”之间的相关性?
id
Date _time
Norms
value
Avg
1
2020-11-30 00:00:00
0
2
2
1
2020-11-30 01:00:00
1
3
2
1
2020-11-30 02:00:00
2
4
2
1
.
.
.
.
1
.
.
.
.
1
.
.
.
.
1
2020-12-2 23:00:00
0
2
2
2
2020-11-14 00:00:00
1
4
3
2
2020-11-14 01:00:00
0
3
3
2
2020-11-14 02:00:00
-1
2
3
2
.
.
.
.
2
.
.
.
.
2
.
.
.
.
2
2020-01-06 23:00:00
1
4
3
*norms= 平均 - 值
计算两组组合各范数的相关系数:
select corr(t1.norms , t2.norms)
from youratble t1
inner join yourtable t2
on t1.id = 1
and t2.id = 2
我在 SQL 中有一个表,我想根据 Norms 列计算 id=1 和 id=2 之间的相关系数 corr()。有什么提示吗?和 2) 我怎样才能找到 id=1 和 id=2 在重叠日期的“标准”之间的相关性?
id | Date _time | Norms | value | Avg |
---|---|---|---|---|
1 | 2020-11-30 00:00:00 | 0 | 2 | 2 |
1 | 2020-11-30 01:00:00 | 1 | 3 | 2 |
1 | 2020-11-30 02:00:00 | 2 | 4 | 2 |
1 | . | . | . | . |
1 | . | . | . | . |
1 | . | . | . | . |
1 | 2020-12-2 23:00:00 | 0 | 2 | 2 |
2 | 2020-11-14 00:00:00 | 1 | 4 | 3 |
2 | 2020-11-14 01:00:00 | 0 | 3 | 3 |
2 | 2020-11-14 02:00:00 | -1 | 2 | 3 |
2 | . | . | . | . |
2 | . | . | . | . |
2 | . | . | . | . |
2 | 2020-01-06 23:00:00 | 1 | 4 | 3 |
*norms= 平均 - 值
计算两组组合各范数的相关系数:
select corr(t1.norms , t2.norms)
from youratble t1
inner join yourtable t2
on t1.id = 1
and t2.id = 2