计算每种活动类型的总数 - oracle - sql

时间:2013-03-10 00:08:32

标签: sql oracle oracle-sqldeveloper

我有3种活动类型,需要显示参与每项活动的人数。例如,我需要查询显示:

  • 活动类型-----------总计
  • 单板滑雪--------- 9
  • 滑雪------------------- 7
  • 雪橇---------------- 5

到目前为止,我编写了以下查询:

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

我需要做的是计算每个类型的每个独特实例 - 类型 - 每种类型的滑雪。我查看了很多资源但找不到任何示例或帮助

1 个答案:

答案 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;