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
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
Please try:
select
MakeDistinct AfterDistinct,
COUNT(*) [Count]
from
YourTable
group by MakeDistinct
SELECT MakeDistinct AS AfterDistinct, COUNT(*) AS [COUNT] FROM tablename
GROUP BY MakeDistinct