hi a quicky Question regarding grouping and counting...
Im counting inmates per Squad in tblInmateProfile in the query below. As well as a few other fields but i cant get the records to group and count properly. just counting the Totals per squad is easy but then counting the "Sub" counts is tricky...
This SQL
Gives me this kind of result...
But i would like to group them all by the Squad and split the medical Confinement into two columns as it can have two values 1 or 2 (and null). The JailStatus is a Boolean and i would like to count that as well.
I would like the result to look like this below. I can get that if i only count the Squads but adding the other fields thats when i mess up things...
Im counting inmates per Squad in tblInmateProfile in the query below. As well as a few other fields but i cant get the records to group and count properly. just counting the Totals per squad is easy but then counting the "Sub" counts is tricky...
This SQL
Code:
SELECT DISTINCTROW tblInmateProfile.tblsquad_ID, Count(*) AS [InmatesTot], tblInmateProfile.tblclass_ID, tblInmateProfile.medicalConfinment, tblInmateProfile.jailStatus
FROM tblInmateProfile
WHERE (((tblInmateProfile.tblstatus_ID)=1) AND ((tblInmateProfile.tblclass_ID)=3))
GROUP BY tblInmateProfile.tblsquad_ID, tblInmateProfile.tblclass_ID, tblInmateProfile.tblclass_ID, tblInmateProfile.gender, tblInmateProfile.medicalConfinment, tblInmateProfile.jailStatus
HAVING (((tblInmateProfile.gender)=1))
ORDER BY tblInmateProfile.tblclass_ID
Code:
squad InmatesTot class medicalConfinment jailStatus
2 60 3 False
2 2 3 1 False
2 2 3 2 False
3 7 3 False
15 64 3 False
15 2 3 1 False
15 3 3 2 False
16 10 3 true
16 1 3 2 False
17 90 3 False
17 1 3 1 False
20 9 3 False
20 1 3 1 False
21 239 3 true
21 7 3 1 False
21 3 3 2 False
22 174 3 False
22 4 3 1 False
22 1 3 2 False
I would like the result to look like this below. I can get that if i only count the Squads but adding the other fields thats when i mess up things...
Code:
squad InmatesTot class medicalConfinment1 medicalConfinment2 jailStatus
2 64 3 2 2 0
3 7 3 0
15 69 3 2 3 0
16 11 3 1 3
17 91 3 1 0
20 10 3 1 0
21 249 3 7 3 4
22 179 3 4 1 0