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)
 Dumb Question

Author  Topic 

dazmiller
Starting Member

2 Posts

Posted - 2005-09-19 : 20:27:11
ok a dumb one here but i need some help.

I have records as such in access db

Name ID StatusCode

Name is a list of names
ID is an ID funnily nuff
StatusCode is a string that can be any of 50 different values.

So i have records like this

Name ID StatusCode
Dan 1 05
Mary 2 25
Dan 1 25
Dan 1 25


I need a query to do the following:

For each name how many 05's are there, how many 25's etc.
so the result should be something like:

Dan 05 Result : 1
Dan 25 Result : 2
Mary 05 Result : 1


Basically i need the count of rows for each person that match the statuscode.

Any ideas?

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-09-19 : 22:32:56
can you post your initial query and tell us where you're encountering an error...



--------------------
keeping it simple...
Go to Top of Page

dazmiller
Starting Member

2 Posts

Posted - 2005-09-19 : 23:08:28
Hi, thanks for the reply.

That is the difficult part.
How do i do this query.

Using access will i have to write some code to iterate thru all the values for one field and query on it. IE (mnemonics) get all the distinct names, then for each name query the count of certain statuscode?

Sorry i am not much help here, its got me stumped.

Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-09-19 : 23:23:14
ok, try reading

select query with group by clause on (name or id) and statuscode, also read count function

in books onLine, you should be fine with this, oh btw, you may want to check Kristen's sticky in the newbie forum, lots of codes there with regards to grouping data

--------------------
keeping it simple...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-20 : 02:08:27
Try this

Select Name,StatusCode, count(*) as Counting from yourTable group by Name,StatusCode


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -