I currently have this in MS Access
:
SELECT ClassID, Count(Component) AS ActiveDuty
FROM tblStudents
WHERE Component = "Active_Duty"
GROUP BY classID;
It gives me the correct answer which looks like this:
ClassID ActiveDuty
006-14 14
007-14 12
008-14 8
But if I want it to look like this what do I need to do?
ClassID ActiveDuty Reserve National Guard
006-14 14 5 6
007-14 12 9 8
008-14 8 7 18
I tried using subqueries like this:
SELECT ClassID, (SELECT COUNT(Component) FROM tblStudents WHERE Component = "ActiveDuty") AS Active_Duty,(SELECT COUNT(Component) FROM tblStudents WHERE Component = "Reserve") AS ArmyReserve,
(SELECT COUNT(Component) FROM tblStudents WHERE Component = "National_Guard") AS NationalGuard
FROM tblStudents
WHERE Component = "Active_Duty"
GROUP BY ClassID;
But this is the result I get:
ClassID ActiveDuty Reserve National Guard
006-14 34 37 29
007-14 34 37 29
008-14 34 37 29