2016-06-01 70 views
0
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' 

什麼是與上述查詢worong。我需要的情況下在哪裏,但該查詢給我錯誤。案例在哪裏mysql不工作

+0

確切地說是你得到的錯誤?你可以發佈嗎? – Crazy2crack

回答

1

請勿在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') 
)