I am using the following SUM query with SQL
SELECT SUM(cost) as total FROM sales where passport =
How would I exclude certain records from the calculation, for example where paid = 1?
I am using the following SUM query with SQL
SELECT SUM(cost) as total FROM sales where passport =
How would I exclude certain records from the calculation, for example where paid = 1?
Hi,
Do you mean like this ?
SELECT SUM(cost) as total FROM sales where (passport = $myPassport AND paid <> 1)
SELECT SUM(cost) as total FROM sales where passport = "12345" and paid <> 1
SELECT SUM(cost) as total
FROM sales
WHERE passport = 12345
AND paid <> 1
Simply
SELECT SUM(cost) as total
FROM sales
WHERE passport = ?
AND paid <> 1
You may also be looking for a group by here
SELECT passport, SUM(cost) as total
FROM sales
WHERE passport = ?
AND paid <> 1
GROUP BY passport
did you mean to get only total that equal to 1 ?
USE : HAVING total = 1