You want to sum the quantities for your orders instead of counting rows.
SELECT name, sum(quantity) as total
FROM 'database'.oc_order_product
GROUP BY name
ORDER BY total DESC;
Question
Sorry about the question title, but it was the best I could think of to describe my problem.
I have an Opencart website in which I need to get the top ten best sellers to display on the page.
I had originally thought that doing a simple query like so:
SELECT name,count(*) as count FROM 'database'.oc_order_product GROUP BY name ORDER BY count DESC;
Which works fine, however I have noticed that some of the records actually have a quantity value to them as well, which obviously would need to be taken into consideration and its at this point I am a bit stumped.
Any help would be greatly appreciated.
La solution
You want to sum the quantities for your orders instead of counting rows.
SELECT name, sum(quantity) as total
FROM 'database'.oc_order_product
GROUP BY name
ORDER BY total DESC;