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? Link to comment https://forums.phpfreaks.com/topic/247371-find-top-items/ 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 Link to comment https://forums.phpfreaks.com/topic/247371-find-top-items/#findComment-1270426 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.