Connecting Tech Pros Worldwide Help | Site Map

Count group by query

Member
 
Join Date: Sep 2007
Posts: 109
#1: Aug 20 '09
I need to write a query which would give me result like this:

name Code1 code2 code3 ect

J Doe 10 2 3

J Smith 8 5 4

and so on...

I have a table which holds a name and this code.

there is muptiple entry of each code with each person i need to find out how many times a perticuler person has recorded a perticular code.

so my table looks like this,

ID name code date
1 j doe code1 1/1/2000
2 j Smith code3 1/1/2000
3 j doe code2 1/1/1900
4 j lulla code10 1/1/2005
5 J doe code1 1/1/2006

so on,

can someone help me with this?

I can do a count individually but that it too time consuming as I have 1000+ names and 100+ codes.

so, is there a way to do all in once?

Thank you in advaned for your help and suggestions.

Thanks,
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#2: Aug 20 '09

re: Count group by query


Looks like a PIVOT/UNPIVOT would help you.

Happy Coding!

--- CK
OraMaster's Avatar
Member
 
Join Date: Aug 2009
Location: Pune, India
Posts: 76
#3: Aug 20 '09

re: Count group by query


Quote:

Originally Posted by arial View Post

I need to write a query which would give me result like this:

name Code1 code2 code3 ect

J Doe 10 2 3

J Smith 8 5 4

and so on...

I have a table which holds a name and this code.

there is muptiple entry of each code with each person i need to find out how many times a perticuler person has recorded a perticular code.

so my table looks like this,

ID name code date
1 j doe code1 1/1/2000
2 j Smith code3 1/1/2000
3 j doe code2 1/1/1900
4 j lulla code10 1/1/2005
5 J doe code1 1/1/2006

so on,

can someone help me with this?

I can do a count individually but that it too time consuming as I have 1000+ names and 100+ codes.

so, is there a way to do all in once?

Thank you in advaned for your help and suggestions.

Thanks,

What did you try so far? Post your SQL's.
Reply