简体   繁体   中英

How can I Ignore zero and negative number

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

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM