Reputation: 3
Where is the mistake in my query
SELECT @Total:=SUM(deposit-cost) as Total FROM `vendor_ledger` Where NOT @Total < 0 GROUP BY
VDR_ID;
Anyone Please Help Me
Upvotes: 0
Views: 45
Reputation: 50308
If you want to ignore any zero or negative deposit-cost
amounts in your sum()
then use a WHERE condition:
SELECT SUM(deposit-cost) as Total
FROM `vendor_ledger`
WHERE deposit-cost > 0
GROUP BY VDR_ID;
If, instead, you are wanting to ignore any Total
where it's less than or equal to 0 then use a HAVING condition:
SELECT SUM(deposit-cost) as Total
FROM `vendor_ledger`
GROUP BY VDR_ID
HAVING Total > 0;
Upvotes: 1