silvercover
silvercover

Reputation: 83

MySQL query to find top items

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

Answers (3)

Imran Omar Bukhsh
Imran Omar Bukhsh

Reputation: 8071

select item_id, sum(count) as total 
from order_list 
group by item_id 
order by total desc 
limit 10

Upvotes: 0

Baz1nga
Baz1nga

Reputation: 15579

SELECT *
FROM table_name 
GROUP BY item_id 
ORDER BY count DESC
LIMIT 10

Upvotes: 0

genesis
genesis

Reputation: 50972

SELECT item_id, SUM(count) FROM order_list GROUP BY item_id ORDER BY SUM(count) DESC LIMIT 0,10

Upvotes: 3

Related Questions