使用两个 with 子句创建 table
Create table using two with clauses
我想创建 table 并使用两个,这是我的代码:
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
"table not existed" 出现错误,请问是因为我的第 2 个 with 子句吗?
一个明显的问题是你的外层 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
.
我想创建 table 并使用两个,这是我的代码:
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
"table not existed" 出现错误,请问是因为我的第 2 个 with 子句吗?
一个明显的问题是你的外层 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
.