使用两个with子句创建表

时间:2015-02-20 00:30:45

标签: sql oracle with-clause

我想创建表并使用两个,这是我的代码:

Create Table profitTry
As
With ctsWithSplit as (select c.Tdate, c.Symbol, c.close * coalesce(s.post/s.pre, 1) as new_close
 from ctsTry c left join splits s 
on c.Tdate = s.Tdate and c.symbol = s.symbol),

delta as
( select a.Tdate as TDate,  a.Symbol as Symbol, a.price-b.price as Pdelta, b.price as oldPrice
   from ctsWithSplit a, ctsWithSplit b
   where a.TDate-b.TDate=1 and a.Symbol=b.Symbol)

select  a.TDate,a.Symbol, (a.delta-coalesce(b.dividend,0))/delta.oldPrice as percentage
From delta a left join dividend b
On a.Tdate=b.Tdate and a.Symbol=b.Symbol

有一个错误说'#34;表不存在",是因为我的第二个条款好吗?

1 个答案:

答案 0 :(得分:1)

一个明确的问题出在您的外部select

select  a.TDate,a.Symbol, (a.delta-coalesce(b.dividend,0))/delta.oldPrice as percentage
-----------------------------------------------------------^
From delta a left join dividend b
On a.Tdate=b.Tdate and a.Symbol=b.Symbol

没有delta。你的意思是a