1

如何制作以下列

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

如下所示

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

3 回答 3

3

通过使用子句对列进行COUNT()分组来使用函数。MakeDistinctGROUP BY

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

输出:

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

看到这个 SQLFiddle

于 2013-05-15T10:40:37.287 回答
0

请试试:

select 
    MakeDistinct AfterDistinct, 
    COUNT(*) [Count] 
from 
    YourTable
group by MakeDistinct
于 2013-05-15T10:40:40.500 回答
0
SELECT MakeDistinct AS AfterDistinct, COUNT(*) AS [COUNT] FROM tablename 
GROUP BY MakeDistinct
于 2013-05-15T11:13:51.023 回答