Can I run a select statement and get the row number if the items are sorted?
I have a table like this:
mysql> describe orders; +-------------+----
You can use MySQL variables to do it. Something like this should work (though, it consists of two queries).
SELECT 0 INTO @x; SELECT itemID, COUNT(*) AS ordercount, (@x:=@x+1) AS rownumber FROM orders GROUP BY itemID ORDER BY ordercount DESC;