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)
 Grouping Similar items to get recordcount

Author  Topic 

ddobbertin
Yak Posting Veteran

51 Posts

Posted - 2006-11-21 : 23:43:07
I am trying to run a query to get a count of similar items. For instance if my sample records are:

location
a_123
a_123_4
b_123
b_123_1
b_123_2
b_456_1
b_456_2

table name:
records

sample query:
select location, count(*) from records group by location

I would like to have the query return:
a_123 - 2
b_123 - 3
b_456 - 2

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-21 : 23:44:36
[code]
select left(location, 5), count(*)
from records
group by left(location, 5)
[/code]


KH

Go to Top of Page

ddobbertin
Yak Posting Veteran

51 Posts

Posted - 2006-11-21 : 23:48:35
Geeze....I am such a bonehead. I should have realized that. I must be thinking of the 4 day weekend already too much. Thanks for the quick response.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-21 : 23:49:53
I would too if i had 4 days weekend ahead


KH

Go to Top of Page
   

- Advertisement -