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)
 Performing a group by on the results of count...

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2000-11-03 : 12:38:36
Matt writes "This one has had me pulling my hair out all morning.

Here is the problem:

I have a list with Names in it. I want a query to tell me how many times a name is listed once, how many times a name is listed twice. etc.

For example, take the list below.

Matt
Matt
Bill
John
John
John
Steve
Paula

I would like the output to be as follows:

1 3
2 1
3 1

As in three names appeared once, 1 appeared twice, 1 appeared three times...

Performing the following query gets me halfway there...

select count(*)
group by Name

which produces...

Matt 2
Bill 1
John 3
Steve 1
Paula 1

If I could perform "select count(*), group by column 2" on the results I would be home!!! But sql won't let me perform a group by on a count!!!!

God I'm confused...can you help me? Temp tables, I'ved tried it all....

Matt."
   

- Advertisement -