简体   繁体   中英

How to count records and display those counted records?

Im trying to have SQL count my records. However, I also need to be able to associate the actual records to that count. This handles the count just fine.

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

ASSIGNED TO actually contains a name. How can I have that name associated to the count so it outputs with the count? I hope that makes sense. If ASSIGNED TO contained 33 records of the name Jim, how can I get the query output to be 33 - Jim?

SELECT [ASSIGNED TO], COUNT([ASSIGNED TO]) AS UserCount
FROM dbo.ECRSurvey
GROUP BY [ASSIGNED TO]
SELECT CAST(CAST(COUNT([ASSIGNED TO]) as varchar(10)) + ' - ' +  [ASSIGNED TO] as varchar(50))  AS UserCount
FROM dbo.ECRSurvey
GROUP BY [ASSIGNED TO]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM