Sql 解析函数上的相关函数
我有一张看起来像的桌子Sql 解析函数上的相关函数,sql,oracle,oracle11g,Sql,Oracle,Oracle11g,我有一张看起来像的桌子 TDate Name Value 20110101 xxx 1.2 20110102 xxx 1.3 ... 20110101 yyy 3.4 20110101 yyy 32.1 我想计算每个名字之间的值的相关性,比如说xxx和yyy之间的值。这是我的密码: Create table corrDEC as Select distinct a.name ASymbol
TDate Name Value
20110101 xxx 1.2
20110102 xxx 1.3
...
20110101 yyy 3.4
20110101 yyy 32.1
我想计算每个名字之间的值的相关性,比如说xxx和yyy之间的值。这是我的密码:
Create table corrDEC as
Select distinct a.name ASymbol,b.name BSymbol,
corr(a.value,b.value) over (partition by a.name,b.name) Correlation
From logprofitDEC a, logprofitDEC b
where a.name<>b.name
Order by 1,2,3 desc;
在where条款中请
如何通过fix where子句来提高我的效率?如果您想要x和y之间的相关性,并且它们各自都有一个关联的日期,那么您需要类似于:
select corr(x, y)
from (select tdate, max(case when name = 'xxx' then value end) as x
max(case when name = 'yyy' then value end) as y
from logprofitDEC
group by tdate
) t;
虽然你可以将其表示为解析函数,但我不认为这样做有什么好处。好吧,corr是对称的,所以你只需要a.name
select corr(x, y)
from (select tdate, max(case when name = 'xxx' then value end) as x
max(case when name = 'yyy' then value end) as y
from logprofitDEC
group by tdate
) t;