1

我有 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

我需要它做的是计算单个 ID 的每个唯一实例,其中类型 - 每种类型的滑雪。我查看了很多资源,但找不到任何示例或帮助

4

1 回答 1

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;
于 2013-03-10T00:33:28.847 回答