SELECT SUM(amount) as tdb
FROM (`v_ledger_details`)
WHERE `debit_credit` = 'DB'
AND `CASE` WHEN transaction_type_id IN(4,5)
THEN billDate < "2016-06-01"
ELSE postingDate < "2016-06-01"
END
AND accountId = '944'
上面的查询有什么问题。我需要 where 中的 case 子句,但该查询给了我错误。
最佳答案
不要在 where
子句中使用 case
。通常只在 select
子句中使用它。然后不要反引号 case
关键字
SELECT SUM(amount) as tdb
FROM v_ledger_details
WHERE `debit_credit` = 'DB'
AND accountId = '944'
AND
(
(transaction_type_id IN (4,5) and billDate < '2016-06-01') OR
(transaction_type_id NOT IN (4,5) AND postingDate < '2016-06-01')
)
关于mysql - mysql 不工作的情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37566070/