如何制作以下列
------------
MakeDistinct
------------
CAT
CAT
CAT
DOG
DOG
PIN
PIN
PIN
PIN
如下所示
------------- -------
AfterDistinct Count
------------- -------
CAT 3
DOG 2
PIN 4
如何制作以下列
------------
MakeDistinct
------------
CAT
CAT
CAT
DOG
DOG
PIN
PIN
PIN
PIN
如下所示
------------- -------
AfterDistinct Count
------------- -------
CAT 3
DOG 2
PIN 4
通过使用子句对列进行COUNT()
分组来使用函数。MakeDistinct
GROUP BY
SELECT MakeDistinct AS AfterDistinct
, COUNT(MakeDistinct) AS Count
FROM MyTable
GROUP BY MakeDistinct
输出:
╔═══════════════╦═══════╗
║ AFTERDISTINCT ║ COUNT ║
╠═══════════════╬═══════╣
║ CAT ║ 3 ║
║ DOG ║ 2 ║
║ PIN ║ 4 ║
╚═══════════════╩═══════╝
请试试:
select
MakeDistinct AfterDistinct,
COUNT(*) [Count]
from
YourTable
group by MakeDistinct
SELECT MakeDistinct AS AfterDistinct, COUNT(*) AS [COUNT] FROM tablename
GROUP BY MakeDistinct