Take a look at this.
Change your query to:
SET @rank=0;
SELECT @rank:=@rank+1 AS rank, itemID, COUNT(*) as ordercount
FROM orders
GROUP BY itemID
ORDER BY ordercount DESC;
SELECT @rank;
The last select is your count.
More Related Contents:
- ROW_NUMBER() in MySQL
- SQL Print the name of all Employees together with the name of their supervisor
- MySQL how to fill missing dates in range?
- Left Outer Join doesn’t return all rows from my left table?
- need to return two sets of data with two different where clauses
- SQL statement is ignoring where parameter
- quick selection of a random row from a large table in mysql
- Strange duplicate behavior from GROUP_CONCAT of two LEFT JOINs of GROUP_BYs
- Column calculated from another column?
- How does MySQL process ORDER BY and LIMIT in a query?
- Generating a random & unique 8 character string using MySQL
- SQL: Repeat a result row multiple times, and number the rows
- sql join two table
- Compare dates in MySQL
- Cast int to varchar
- Invalid default value for ‘dateAdded’
- Import SQL file into mysql
- MySQL SELECT last few days?
- Split a string and loop through values in MySQL stored procedure
- How to create dummy variable columns for thousands of categories in Google BigQuery?
- how to cast the hexadecimal to varchar(datetime)?
- MySQL Select Query – Get only first 10 characters of a value
- Most efficient way to store IP Address in MySQL [duplicate]
- Postgres LEFT JOIN with WHERE condition
- SQL date format convert? [dd.mm.yy to YYYY-MM-DD]
- mysql select id and name from other table and join query
- How do you force mysql LIKE to be case sensitive? [duplicate]
- #1060 – Duplicate column name ‘id’
- In what order are MySQL JOINs evaluated?
- Update multiple rows with multiple ‘where’ clauses for each individual row