I have a table (apples) containing:
cid date_am date_pm
----------------------
1 1 1
2 2 1
3 1 3
1 1 2
I asked a question earlier (badly) about how I would rank the customers in order of the number of ones(1) they had. The solution was (based on one column):
SELECT cid, sum( date_pm ) AS No_of_ones
FROM apples
WHERE date_am =1
GROUP BY cid
ORDER BY no_of_ones DESC
This works great for one column but how would I do the same for the sum of the two columns. ie.
SELECT cid, sum( date_pm ) AS No_of_ones
FROM apples
WHERE date_am =1
add to
SELECT cid, sum( date_am ) AS No_of_ones
FROM apples
WHERE date_pm =1
GROUP by cid
ORDER by no_of_ones(added)
hope I've managed to make that clear enough for you to help -thanks