我有以下查询:
select * from isg.tdbFutures f, isg.tdbOption e
where
f.contract = 306121 and
e.underlier = f.entityID
哪个会返回:
entityID lastTradeDate expiration firstTradeDate contract lastTradeDate underlier isPut expiration strike entityID optionMetricsID expirationCycle
----------- ---------------- ------------- ----------------- ----------- ---------------- ------------ -------- ------------- --------- ----------- ------------------ ------------------
311320 3/1/2018 3/1/2018 6/22/2017 306123 12/22/2017 311320 false 12/22/2017 100 368145 0 monthly
311320 3/1/2018 3/1/2018 6/22/2017 306123 12/22/2017 311320 false 12/22/2017 106 368146 0 monthly
311320 3/1/2018 3/1/2018 6/22/2017 306123 12/22/2017 311320 false 12/22/2017 120 368147 0 monthly
我想构建一个字符串,将其插入到另一个表中,该表以isPut列为条件。这是我的尝试:
select * from isg.tdbFutures f, isg.tdbOption e
where
f.contract = 306123 and
e.underlier = f.entityID
CASE isPut
WHEN false THEN 'FI_US_M Call'
WHEN true THEN 'FI_US_M Put'
END
但是,出现以下错误:
>[Error] Script lines: 45-52 ------------------------
SQL Anywhere Error -131: Syntax error near 'false' on line 6
Msg: 102, Level: 15, State: 0
Line: 0
我要插入的表,其中category
是我的条件字符串,entityID
是我的f.contract
值:
category entityID
----------------- -----------
US Equity 66281
US Fixed Income 66283
AUD 66359
答案 0 :(得分:2)
您似乎想要的查询是:
select f.*, o.*,
(case when isPut then 'FI_US_M Put'
else 'FI_US_M Call'
end) as new_column
from isg.tdbFutures f join
isg.tdbOption o
on o.underlier = f.entityID
where f.contract = 306123;
注意:
JOIN
语法。 从不在FROM
子句中使用逗号。select
中的所有列。e
更改为o
。case
表达式属于select
。答案 1 :(得分:0)
正如@GordonLinoff所指出的,它不应该像这样:
select
*,
CASE isPut
WHEN false THEN 'FI_US_M Call'
WHEN true THEN 'FI_US_M Put'
END as my_new_column
from isg.tdbFutures f, isg.tdbOption e
where
f.contract = 306123 and
e.underlier = f.entityID
答案 2 :(得分:0)
我想你想要这个
从isg.tdbFutures f,isg.tdbOption e中选择*, 案件 当isPut = false时'FI_US_M通话' 否则'FI_US_M Put'结束 哪里 f。合同= 306123和 e.underlier = f.entityID
答案 3 :(得分:0)
如果要插入到另一个表中,那不是吗?
insert new_column_from_case = CASE isPut WHEN false THEN 'FI_US_M Call'
WHEN true THEN 'FI_US_M Put'
END
new_f_contract = f.contract
into another_table
from isg.tdbFutures f, isg.tdbOption e
where f.contract = 306123
and e.underlier = f.entityID