silvercover Posted September 18, 2011 Share Posted September 18, 2011 Hi, I have a table called order_list with the following fields - order_id - user_id - item_id - count - date - order_status 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? Quote Link to comment Share on other sites More sharing options...
TrueColors Posted September 18, 2011 Share Posted September 18, 2011 Not guaranteed to work but what does produce: SELECT SUM(`count`) as itemcount, item_id FROM order_list GROUP BY item_id ORDER BY itemcount DESC LIMIT 10 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.