Reputation: 83
I have a table called order_list with the following fields
every time users place order, this table used to save order details. so how can I write my SQL query to find top 10 items based on the sum of ordered count?
Upvotes: 0
Views: 335
Reputation: 8071
select item_id, sum(count) as total
from order_list
group by item_id
order by total desc
limit 10
Upvotes: 0
Reputation: 15579
SELECT *
FROM table_name
GROUP BY item_id
ORDER BY count DESC
LIMIT 10
Upvotes: 0
Reputation: 50972
SELECT item_id, SUM(count) FROM order_list GROUP BY item_id ORDER BY SUM(count) DESC LIMIT 0,10
Upvotes: 3