SQL中所有变量与目标变量的关联

问题描述 投票:0回答:1

我有一个包含270列的表格。我选择了其中一个作为目标变量,我想编写一个查询来查找每个变量与目标列的相关性。有没有一种方法可以不对corr函数中的列名进行硬编码?我正在使用Oracle SQL。

sql oracle correlation
1个回答
1
投票

不是。但是在Oracle 12+中,您可能会发现这更简单:

select x.which, corr(x.target, x.source)
from t cross join lateral
     (select 'source001' as which, target, source1 as source from dual union all
      select 'source002' as which, target, source2 as source from dual union all
      . . .
      select 'source270' as which, target, source270 as source from dual
     ) x
group by which;

对于just相关,这并不比单独列出corr()函数简单。但是您可以轻松地添加更多统计信息-例如min()max()count()-无需重复所有列(或遇到列限制)。

© www.soinside.com 2019 - 2024. All rights reserved.