开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜