TSQL返回Guid在列中发生的最多

时间:2009-04-27 05:11:22

标签: sql tsql

如果我有一个包含两列的表格,例如名称和ID,其中ID是GUID,如何从第2列返回最多发生的Guid值?

2 个答案:

答案 0 :(得分:4)

未测试:

SELECT TOP 1 ID, COUNT(*) AS CountOfRows
FROM UnknownTable
GROUP BY ID
ORDER BY CountOfRows DESC

答案 1 :(得分:3)

SELECT TOP 1 ID, COUNT(ID) AS count
FROM IDTable
GROUP BY ID
ORDER BY count DESC