使用 PostgreSQL 计算相关系数?

发布于 2024-09-04 17:52:02 字数 210 浏览 7 评论 0原文

我已经弄清楚了如何计算两个字段之间的相关系数(如果两个字段都在同一个表中):

SELECT corr(column1, column2) FROM table WHERE <my filters>;

...但是当列来自不同的表时我无法弄清楚如何执行此操作(我需要应用相同的过滤器)到两个表)。

有什么提示吗?

I have worked out how to calculate the correlation coefficient between two fields if both are in the same table:

SELECT corr(column1, column2) FROM table WHERE <my filters>;

...but I can't work out how to do it when the columns are from different tables (I need to apply the same filters to both tables).

Any hints, please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风为裳 2024-09-11 17:52:02

如果这些表彼此相关以便您可以将它们连接起来,那就相当简单了。只需加入它们并进行关联即可:

SELECT corr(t1.col1, t2.col2)
FROM table1 t1
     JOIN table2 t2
         ON t1.join_field = t2.join_field
WHERE
     <filters for t1>
     AND
     <filters for t2>

如果它们不是,那么您应该如何找出要在其上运行 corr 的每个表中的哪些字段组合?

If the tables are related to one another such that you can join them, it's fairly simple. Just join them and do the correlation:

SELECT corr(t1.col1, t2.col2)
FROM table1 t1
     JOIN table2 t2
         ON t1.join_field = t2.join_field
WHERE
     <filters for t1>
     AND
     <filters for t2>

If they're not, then how are you supposed to find out which combination of fields from each table you want to run corr on?

锦爱 2024-09-11 17:52:02

试试这个

SELECT corr(t1.column1, t2.column2) 
FROM table1 t1
join table2 t2 on t1.SomeColumn = t2.SomeColumn 
WHERE t1.<my filters>
AND t2.<my filters>;

try this

SELECT corr(t1.column1, t2.column2) 
FROM table1 t1
join table2 t2 on t1.SomeColumn = t2.SomeColumn 
WHERE t1.<my filters>
AND t2.<my filters>;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文