分析功能并选择特定行

时间:2015-02-26 17:04:40

标签: sql oracle oracle11g

我有一张桌子

Tdate        Name      value
20130101     xxx        1.2
20130102     xxx        1.4
...
20130101     yyy        1.3
20130102     yyy        2.3

我想计算2013年1月每个名字之间的价值相关性,并列出前20名。这是我的代码:

With targetRow as (
Select  XXX
Where tDate is “20130131”)

Select  a.name, b.name, corr(a.value,b.value) over (partition by name
Range  between 31  preceding and targetRow)  Correlation
From logprofittest a, logprofittest b
Order by correlation

以下是问题:

(1)如何完成我的with子句(或者有更好的方法)。我的Tdate存储为整数?)

(2)如果我的桌子太大而加入本身太贵,如何只列出前100名?

更新:对不起,我稍微修改了一下代码。

Select  a.Symbol, b.Symbol, corr(a.logp,b.logp) over (partition by a.symbol,b.symbol)  Correlation
From logprofittest a, logprofittest b
where a.Symbol<>b.symbol
And  To_date(a.Tdate,'YYYYMMDD') between  DATE'2013-12-01' AND DATE'2013-12-31'
and  To_date(b.Tdate,'YYYYMMDD') between  DATE'2013-12-01' AND DATE'2013-12-31'
and  To_date(a.Tdate,'YYYYMMDD')=To_date(b.Tdate,'YYYYMMDD')
Order by correlation desc;

0 个答案:

没有答案