How to get number of duplicate Rows of DISTINCT co

2019-08-08 17:13发布

How can I make the following Column

------------
MakeDistinct
------------
CAT
CAT
CAT
DOG
DOG
PIN
PIN
PIN
PIN

As Shown Below

-------------   -------
AfterDistinct   Count
-------------   -------
CAT              3
DOG              2
PIN              4

3条回答
看我几分像从前
2楼-- · 2019-08-08 18:15
SELECT MakeDistinct AS AfterDistinct, COUNT(*) AS [COUNT] FROM tablename 
GROUP BY MakeDistinct
查看更多
姐就是有狂的资本
3楼-- · 2019-08-08 18:18

Use COUNT() function by grouping MakeDistinct column using GROUP BY clause.

  SELECT MakeDistinct AS AfterDistinct
       , COUNT(MakeDistinct) AS Count
    FROM MyTable
GROUP BY MakeDistinct

Output:

╔═══════════════╦═══════╗
║ AFTERDISTINCT ║ COUNT ║
╠═══════════════╬═══════╣
║ CAT           ║     3 ║
║ DOG           ║     2 ║
║ PIN           ║     4 ║
╚═══════════════╩═══════╝

See this SQLFiddle

查看更多
beautiful°
4楼-- · 2019-08-08 18:18

Please try:

select 
    MakeDistinct AfterDistinct, 
    COUNT(*) [Count] 
from 
    YourTable
group by MakeDistinct
查看更多
登录 后发表回答