PostgreSQL CASE,那么ELSE END错误

时间:2015-04-21 09:15:26

标签: postgresql

当我们使用v9.1时,我工作得很好,但升级到v9.4后,以下失败。

SELECT   a.account_id 
         ( 
                select round(cast(sum(WHEN c.transaction_type = 'Ranger' THEN c.original_currency ELSE c.original_currency * -1
         end)) AS NUMERIC), 
                       2) 
FROM     account_transaction AS c 
WHERE    a.account_id = c.account_id 
GROUP BY c.account_id) 
AS 
  balance_amount 
  FROM account 
AS 
  a LEFT JOIN account_type 
AS 
  b ON a.account_type_id = b.account_type_id 
  WHERE ( 
    b.description >= 'Boomberang' AND b.description <= 'Boomberang' 
  );

WHEN

附近的

语法错误

我用Google搜索但无法解决问题。请帮忙。

2 个答案:

答案 0 :(得分:4)

您似乎错过了CASE关键字,请尝试以下方式:

(CASE WHEN c.transaction_type = 'Ranger' THEN c.original_currency ELSE c.original_currency * -1 END)

答案 1 :(得分:1)

您的意思是CASE WHEN而不是WHEN吗?