Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 COUNT Function

Author  Topic 

paradocity
Starting Member

2 Posts

Posted - 2001-02-20 : 12:01:17
I fully understand how to perform a basic SELECT COUNT(*) query but I need something a bit more advanced and don't know how to do it.

For simplicity, I have a single table with single column named UserName, the data kept in this column is a log of the usernames used to access a simple website. I want to perform a COUNT on this column NOT to get the total number of usernames in the table but rather to find out how many times each username appears in the table. For example, output from the query would look like this.

UserName Count
-------- -----
bill 7
jane 22
john 3
mike 10

I would like to perform this in a single query statement but don't know if that is possible. I would like to avoid loops or cursors if possible too. Can anyone shed some light on my delimma?

Thank you.
   

- Advertisement -