SELECT DISTINCTROW P.ID, First(I.Type) AS [First Of Type], Count(*) AS [Count Of I]
FROM P INNER JOIN I ON P.[ID] = I.[P ID]
GROUP BY P.ID;
Where the types are "a" and "b". My query will return:
ID First of Type Count of I
1 a 6
This is great but what I'd like is:
ID First of Type Count of I Count of a Count of b
1 a 6 2 4
I can't figure out how to make this work. Any help would be much appreciated!
EDIT:
I'm doing this in Access. My tables look like:
Table P
ID Name
1 Alice
2 Bob
Table I
ID P ID Type
1 1 a
2 1 b
3 1 a
4 1 b
5 1 b
6 1 b
7 2 b
And I want to return
ID First of Type Count of I Count of a Count of b
1 a 6 2 4
2 b 1 0 1
Hope this makes sense. I tried to use the "union all" syntax but no luck with what I'm trying so far.