Here's a query I have:
SELECT
C.CLIENTNUMBER,
(SELECT SUM(B.FEES) WHERE B.TYPE IN ('1', '2')) AS TOTALFEES
FROM CLIENTS C
INNER JOIN BILLS B ON B.CLIENTNUMBER = C.CLIENTNUMBER
GROUP BY C.CLIENTNUMBER
This is pretty straightforward, but here's the rub. If B.TYPE is either 1 or 2, I want to add B.FEES to TOTALFEES. But if it's 3, I want to subtract B.FEES from TOTALFEES.
Any ideas on how to do this ? Thanks
Aucun commentaire:
Enregistrer un commentaire