group by query trouble

  • Thread starter Thread starter ckgriff2
  • Start date Start date
C

ckgriff2

I'm trying to run a query that counts the number of people with
hemoglobin of type SS, type SC, and then all others. There are about
12 different kinds of types.

Basically I want a count for SS, a count for SC, and then a count that
totals all the others into one count. Hopefully that makes sense.

I'm using group by for the SS and SC which works great, but I'm not
sure how to tell it to add up the others.
 
I'm not a big fan of nested IIf statements, but this should work after you
put in the proper field and table names:

SELECT
IIf([Hemoglobin]="SC","SC",IIf([Hemoglobin]="SS","SS","Other")) AS
HemoglobinType,
Count([HemoglobinType]) AS PeopleWith
FROM YourTable
GROUP BY IIf([Hemoglobin]="SC","SC",IIf([Hemoglobin]="SS","SS","Other"));
 
I'm trying to run a query that counts the number of people with
hemoglobin of type SS, type SC, and then all others. There are about
12 different kinds of types.

Basically I want a count for SS, a count for SC, and then a count that
totals all the others into one count. Hopefully that makes sense.

I'm using group by for the SS and SC which works great, but I'm not
sure how to tell it to add up the others.


SELECT IIf(htype IN("SS","SC"), htype, "Other"),
Count(*) As grpcount
FROM table
GROUP BY IIf(htype IN("SS","SC"), htype, "Other")
 
Back
Top