简体   繁体   English

计算每种活动类型的总数-Oracle-SQL

[英]Count total of each activity type - oracle - sql

I have 3 activity types and need to display how many people have taken part in each event. 我有3种活动类型,需要显示每个活动有多少人参加。 So for example I need the query to display: 因此,例如,我需要查询来显示:

  • activity type ----------- total 活动类型-----------总计
  • Snowboarding --------- 9 单板滑雪--------- 9
  • Skiing ------------------- 7 滑雪------------------- 7
  • Sledging ---------------- 5 雪橇---------------- 5

So far I have written the following query: 到目前为止,我已经编写了以下查询:

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;

This is obviously wrong and comes up with the error " not a single group function " 这显然是错误的,并出现错误“ not a single group function

What I need it to do is count each unique instances of individual ID where type - skiing for each type. 我需要做的是计算每个ID的每个唯一实例的类型-每个类型的滑雪。 I have looked at many resources but cannot find any examples or help 我看过很多资源,但找不到任何示例或帮助

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM