我很新的红移,我一直试图做一个嵌套的情况下,当条件在这里,但我得到一个语法错误
ERROR:语法错误
:
ELSE ROUND((last_bid * positions), 2))
我不确定什么是错的,因为我熟悉Python,我很确定这就是嵌套条件的工作方式
SELECT
*,
CASE
WHEN asset_type = 'EQUITY'
THEN (CASE
WHEN positions < 0 THEN ROUND((positions * last_ask), 2)
ELSE ROUND((last_bid * positions), 2))
ELSE ROUND((positions * last_ask/100), 2)
END AS MARKET_VALUE
FROM
base_report
您应该结束嵌套的CASE,像这样:
ELSE ROUND((last_bid * positions), 2)
END
)
SELECT *,
CASE
WHEN asset_type = 'EQUITY' THEN
(
CASE
WHEN positions < 0 THEN
ROUND((positions * last_ask), 2)
ELSE ROUND((last_bid * positions), 2)
END )
ELSE ROUND((positions * last_ask / 100), 2)
END AS MARKET_VALUE
FROM base_report
请让我知道这是否有效
请试试:
SELECT *
, CASE
WHEN asset_type ='EQUITY' THEN
(CASE
WHEN positions < 0 THEN ROUND((positions * last_ask),2)
ELSE ROUND((last_bid * positions),2) end)
ELSE ROUND((positions * last_ask/100),2)
END as MARKET_VALUE
FROM base_report