1

我试图让 SQL 计算我的记录。但是,我还需要能够将实际记录与该计数相关联。这可以很好地处理计数。

SELECT COUNT([ASSIGNED TO AS UserCount
FROM dbo.ECRSurvey
GROUP BY [ASSIGNED TO]

ASSIGNED TO 实际上包含一个名称。我怎样才能将该名称与计数相关联,以便它与计数一起输出?我希望这是有道理的。如果 ASSIGNED TO 包含 33 条名为 Jim 的记录,我怎样才能让查询输出为 33 - Jim?

4

2 回答 2

5
SELECT [ASSIGNED TO], COUNT([ASSIGNED TO]) AS UserCount
FROM dbo.ECRSurvey
GROUP BY [ASSIGNED TO]
于 2013-10-29T21:07:41.083 回答
2
SELECT CAST(CAST(COUNT([ASSIGNED TO]) as varchar(10)) + ' - ' +  [ASSIGNED TO] as varchar(50))  AS UserCount
FROM dbo.ECRSurvey
GROUP BY [ASSIGNED TO]
于 2013-10-29T21:11:14.073 回答