lovejaeeun
Technical User
Hi,
I have a FAMILY table and a CHILD table with a one to many remlationship where a FAMILY can have multiple CHILD.
The FAMILY ID is the FK in the CHILD table.
1)
I want to write a query that would display the following as a result: (how many familes have 'x' amount of children)
# children families
0 15
1 98
2 253
3 194
4 110
etc.
2)
I also want to write a query to find out the average number of children a family has.
The closest I have got is:
SELECT Count(*)
FROM CHILD
GROUP BY FamilyID
HAVING Count(*) = 1;
*And then I have to repeat this for 2 children, 3 children, 4 etc..
Thank you!
I have a FAMILY table and a CHILD table with a one to many remlationship where a FAMILY can have multiple CHILD.
The FAMILY ID is the FK in the CHILD table.
1)
I want to write a query that would display the following as a result: (how many familes have 'x' amount of children)
# children families
0 15
1 98
2 253
3 194
4 110
etc.
2)
I also want to write a query to find out the average number of children a family has.
The closest I have got is:
SELECT Count(*)
FROM CHILD
GROUP BY FamilyID
HAVING Count(*) = 1;
*And then I have to repeat this for 2 children, 3 children, 4 etc..
Thank you!