sql - SQL中所有变量与目标变量的相关性
问题描述
我有一张有 270 列的表。我选择了其中一个作为目标变量,我想编写一个查询,分别与目标列查找每个变量的相关性。有没有办法在不硬编码 corr 函数中的列名的情况下做到这一点?我正在使用 Oracle SQL。
解决方案
并不真地。但在 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;
对于相关性,这并不比单独列出corr()
函数更简单。但是您可以轻松地添加更多统计信息——比如 、min()
或max()
——count()
而无需重复所有列(或遇到列限制)。
推荐阅读
- arrays - 如何转换嵌套在 Postgres 中另一个数组内的对象内的 JSON 数组?
- .net - 使用 .net core 和 Angular 托管 Web 应用程序的最佳方式是什么?
- c# - 如何将四元数转换为角度?
- java - 如果语句在 Android OnClick 中不起作用
- mysql - 如果未找到,则设置值或 NULL
- python - 错误的空间相似度结果
- javascript - 在 HTML 文本之后添加锚点
- c# - 使用 Interop 传递 SharePoint 凭据以访问 Excel 文件?
- android - 如何获取用户已经参与的 MUC 房间列表?
- ios - 我可以在方法参数中使用赋值运算符吗