我有3种活动类型,需要显示参与每项活动的人数。例如,我需要查询显示:
到目前为止,我编写了以下查询:
SELECT type_of_activity, COUNT (DISTINCT individual_id)
FROM activities, events, book_activity
WHERE activities.activity_code = events.activity_code
AND events.event_id = book_activity.event_id;
这显然是错误的,并出现错误“not a single group function
”
我需要做的是计算每个类型的每个独特实例 - 类型 - 每种类型的滑雪。我查看了很多资源但找不到任何示例或帮助
答案 0 :(得分:1)
SELECT a.type_of_activity, COUNT(ba.individual_id)
FROM BOOK_ACTIVITY ba
JOIN EVENTS e
ON e.event_id = ba.event_id
JOIN ACTIVITIES a
ON a.activity_code = e.activity_code
GROUP BY a.type_of_activity;