嗨,我正在做一个项目,我想根据表中的其他属性和它的关联对一些值进行求和。到目前为止,我有:
SELECT (
SUM(
(CASE WHEN models.type = 'type_1' THEN -1 ELSE 1 END) *
(CASE WHEN models.currency_id = other_models.currency_id THEN ROUND(models.amount * other_models.conversion, 2) ELSE models.amount END)
) AS difference
)
但是这给了我一个语法错误,但是我不确定为什么?任何帮助都是最好的。
发布于 2018-02-15 21:29:28
一种可能是SELECT
中有其他列。整个表达式不需要用括号括起来:
SELECT SUM((CASE WHEN models.type = 'type_1' THEN -1 ELSE 1 END) *
(CASE WHEN models.currency_id = other_models.currency_id THEN ROUND(models.amount * other_models.conversion, 2) ELSE models.amount END)
) AS difference
我在表达式本身中看不到明显的错误。
https://stackoverflow.com/questions/48808433
复制相似问题