View Full Version : Group and Count field values


Baldrick
02-21-2002, 04:48 AM
I have 3 fields that I'm trying to query. They are LOB, DIV and Project_Stat_Code. I am trying to count 4 values in Project_Stat_Code ("IP", "OH", "PD" and "C") and Group them by LOB, then by DIV.

I'm not sure how to approach this. Should I generate a single query for each Project_Stat_Code value and then query against those queries? Or, can I do it all in a single query?

EndersG
02-21-2002, 07:43 AM
SELECT LOB, DIV, Count(Project_Stat_Code) AS CountOfProject_Stat_Code
FROM [TableName]
GROUP BY LOB, DIV;

HTH,

Edward

Baldrick
02-26-2002, 06:54 AM
Thanks Edward

What I actually needed was a crosstab:

TRANSFORM Count(qryProjectStatus.Project_Stat_Code) AS CountOfProject_Stat_Code
SELECT qryProjectStatus.LOB, qryProjectStatus.Div
FROM qryProjectStatus
GROUP BY qryProjectStatus.LOB, qryProjectStatus.Div
PIVOT qryProjectStatus.Project_Stat_Code;

For the benefit of others...