Get maximum count of a value in a column
If I开发者_StackOverflow have a simple database table of names like so:
--------------
| NAME |
--------------
| Andrew |
| Bill |
| Andrew |
| Claire |
| Claire |
| Andrew |
--------------
Is it possible to run a query that would produce a tally of the names? i.e.
-----------------------
| NAME | COUNT |
-----------------------
| Andrew | 3 |
| Claire | 2 |
| Bill | 1 |
-----------------------
Like this:
SELECT Name, COUNT(Name) FROM TABLE GROUP BY Name
You may want this to get the max:
SELECT Name, COUNT(Name) AS c
FROM TABLE
GROUP BY Name
ORDER BY c DESC
精彩评论