我有两个表T1
Date Symbol high low close
xxx yyy 1.2 1.0 1.14
和表T2
Date Symbol factor
xxx yyy 1.2
我想从T1创建一个只有三个字段的新表
Date Symbol new_close
xxx yyy 1.4
其中new_close = iff(日期和符号匹配T1和T2,关闭*因子,关闭)。 这是我的代码:
Select a.Tdate, a.Symbol , a.close*(b.factor as fixP
Into ctsWithSplit
From cts a inner join split b
Where a.Tdate=b.Tdate and a.Symbol=b.Symbol
Union
Select Tdate,Symbol,close
From cts
Where not in ctsWithSplit
我觉得必须有一个简单的方法吗?请问如何解决?
答案 0 :(得分:1)
我想你想要一个left join
和create table as
:
create table ctsWithSplit as
select c.Tdate, c.Symbol,
c.close * coalesce(s.factor, 1) as new_close
from cts c left join
splits s
on c.Tdate = s.Tdate and c.symbol = s.symbol;