I have a 40,000 record database which consists of the following fields:
ID, STATE, TYPE
The type field contains one of 5 distinct values.
I want to run a query where I group the records by state and also get counts of each distinct type value. The resulting output I want is as follows:
STATE, TYPE_A, TYPE_B, TYPE_C, TYPE_D, TYPE_E, TYPE_ALL
type_all is a total count of records for that state.
My SQL Thus far looks like this:
SELECT TABLE1.STATE,
COUNT(TABLE1.type) as TYPE_ALL,;
COUNT(TABLE1.type='A') as TYPE_A,;
COUNT(TABLE1.type='B') as TYPE_B,;
COUNT(TABLE1.type='C') as TYPE_C,;
COUNT(TABLE1.type='D') as TYPE_D,;
COUNT(TABLE1.type='E') as TYPE_E;
FROM TABLE1;
GROUP BY TABLE1.STATE
However, all count values are the same. Any ideas of what I'm doing wrong and how I might fix it?
Thanks, in advance, for your help!
Michael
ID, STATE, TYPE
The type field contains one of 5 distinct values.
I want to run a query where I group the records by state and also get counts of each distinct type value. The resulting output I want is as follows:
STATE, TYPE_A, TYPE_B, TYPE_C, TYPE_D, TYPE_E, TYPE_ALL
type_all is a total count of records for that state.
My SQL Thus far looks like this:
SELECT TABLE1.STATE,
COUNT(TABLE1.type) as TYPE_ALL,;
COUNT(TABLE1.type='A') as TYPE_A,;
COUNT(TABLE1.type='B') as TYPE_B,;
COUNT(TABLE1.type='C') as TYPE_C,;
COUNT(TABLE1.type='D') as TYPE_D,;
COUNT(TABLE1.type='E') as TYPE_E;
FROM TABLE1;
GROUP BY TABLE1.STATE
However, all count values are the same. Any ideas of what I'm doing wrong and how I might fix it?
Thanks, in advance, for your help!
Michael