tags:

views:

46

answers:

5

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?

A: 

Hi,

Do you mean like this ?

SELECT SUM(cost) as total FROM sales where (passport = $myPassport AND paid <> 1)
Trefex
*excluding* where paid = 1...
CJM
Yes yes, already corrected it...Gimme a chance instead of downvoting me :( :)
Trefex
A: 
SELECT SUM(cost) as total FROM sales where passport = "12345" and paid <> 1
peter_mcc
A: 
SELECT SUM(cost) as total 
FROM sales 
WHERE passport = 12345
AND paid <> 1
CJM
+1  A: 

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
Cruachan
A: 

did you mean to get only total that equal to 1 ?

USE : HAVING total = 1

Haim Evgi