Merry Xmas.开发者_Go百科 Can anyone help me to come up with the query for this particular scenario: ~I need to produce a list of Activities showing the number of Children of each gender registered for each activity. What would be the query? Thank you. TABLE STRUCTURE AS FOLLOWS: There is ACTIVITY, CHILD, CHILD ACTIVITY TABLE.
ACTIVITY TABLE
( activity_id[Primary Key],
Activity)
CHILD TABLE
( child_id[Primary Key],
child_name,
child_gender,
child_dob)
CHILD ACTIVITY TABLE
( activity_id[Composite Primary Key],
child_id[Composite Primary Key]
Activity/Day Of Week)
SELECT a.activity_id, a.Activity, c.child_gender, COUNT(*)
FROM ACTIVITY a
JOIN [CHILD ACTIVITY] ca ON a.activity_id = ca.activity_id
JOIN CHILD c ON ca.child_id = c.child_id
GROUP BY a.activity_id, a.Activity, c.child_gender
精彩评论