I have the following data in a table called 'customers':
accmanid custid billone billltwo
1 1 126.9 514.6
1 2 264.73 108
1 3 130.5 514.6
1 4 137.82 514.6
2 10 126.9 514.6
2 11 126.9 375.48
2 12 126.9 117.55
2 13 126.9 261.66
3 19 130.5 117.55
3 20 130.5 117.55
3 21 264.73 117.55
3 22 165.43 117.55
and I am using the following query to retrieve the top three customers for 'accmanid' 1:
SELECT accmanid, custid, SUM(billone + billtwo) AS
total FROM customers WHERE accmanid = 1 ORDER BY total DESC LIMIT 3
This outputs five rows ordered by the 'total' where accman = 1.
Here is my question:
How can I write the query to output three rows for EACH accmanid; Im not sure how to do such without the WHERE clause or some kind of loop, whcih Ive read is bad.
If you need more information or clarification, please ask and Il be happy to assist.
Thanks so much for your help and for this great site.