Knowledgebase
SQL question: Select COUNT(*) and then order by COUNT
Posted by riverpast, 03-14-2007, 02:34 PM | This works:
select product_id, count(*) from order_line group by product_id
It shows the product and how many sales each product has.
However, I want to sort by the product sales, so I am trying:
select product_id, count(*) from order_line group by product_id order by count(*)
It doesn't like "order by count(*)". I tried many variations and just couldn't figure out how to make it sort by the count
Of course, "orber by product_id" would work.
How do I make it sort by the COUNT()?
By the way, I am using MySQL
|
Posted by foobic, 03-14-2007, 03:49 PM |
|
Posted by riverpast, 03-14-2007, 03:56 PM | Thanks. Exactly what I needed.
|
|
Add to Favourites
Print this Article |
Also Read