Jump to content

Recommended Posts

???

 

I have a database holding a list of customer`s orders, i thought it would be neat to show the top 5 selling products on our website.

 

Now i have a recordset that counts each product sold which COUNTS by model_ID and GROUPS BY model_ID

 

But heres the problem i wish to show the highest COUNT descending??

So the highest COUNT is at the top and show five records giving me the Top 5 Selling models?

 

At the moment it lists them in model order as you would expect..

 

here is the rough Recordset:-

 

SELECT *, COUNT(mode_ID)
FROM order_item,products
WHERE products.prod_ID=order_item.mode_ID
GROUP BY mode_ID

 

??? Thanks Paul.

Link to comment
https://forums.phpfreaks.com/topic/77120-can-you-sort-a-list-of-counted-results/
Share on other sites

[sOLVED]

 

SELECT *, COUNT(mode_ID) As Number
FROM order_item,products
WHERE products.prod_ID=order_item.mode_ID
GROUP BY mode_ID
ORDER BY Number DESC

 

Thanks to http://www.webdevelopersnotes.com/tutorials/sql/online_mysql_training_course_counting.php3

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.