With this query
SELECT
product, customer, sum(sales) as topSales
FROM
invoices
WHERE
product in (//lots of product id's here)
GROUP BY
product, customer
ORDER BY
topSales DESC
I get a result set containing all buyers for a product, in order of sales descending.
PRODUCT CUSTOMER topSales
=============================
banana Chris 50.35
banana Eric 34.87
cookie Emmy 54.54
apple John 78.67
banana Derek 33.87
banana Sally 21.76
apple Henry 65.78
cookie Yoyo 24.67
milk Chris 30.43
milk Henry 22.43
I only want the top buyer for each product, it should look like this
PRODUCT CUSTOMER topSales
=============================
banana Chris 50.35
cookie Emmy 54.54
apple John 78.67
milk Chris 30.43
How can I get the result like this? I need to get distinct products, but only for the top buyer.