1
+ -- 1355. Activity Participants
2
+ --
3
+ -- Table: Friends
4
+ --
5
+ -- +---------------+---------+
6
+ -- | Column Name | Type |
7
+ -- +---------------+---------+
8
+ -- | id | int |
9
+ -- | name | varchar |
10
+ -- | activity | varchar |
11
+ -- +---------------+---------+
12
+ -- id is the id of the friend and primary key for this table.
13
+ -- name is the name of the friend.
14
+ -- activity is the name of the activity which the friend takes part in.
15
+ -- Table: Activities
16
+ --
17
+ -- +---------------+---------+
18
+ -- | Column Name | Type |
19
+ -- +---------------+---------+
20
+ -- | id | int |
21
+ -- | name | varchar |
22
+ -- +---------------+---------+
23
+ -- id is the primary key for this table.
24
+ -- name is the name of the activity.
25
+ --
26
+ --
27
+ -- Write an SQL query to find the names of all the activities with neither maximum, nor minimum number of participants.
28
+ --
29
+ -- Return the result table in any order. Each activity in table Activities is performed by any person in the table Friends.
30
+ --
31
+ -- The query result format is in the following example:
32
+ --
33
+ -- Friends table:
34
+ -- +------+--------------+---------------+
35
+ -- | id | name | activity |
36
+ -- +------+--------------+---------------+
37
+ -- | 1 | Jonathan D. | Eating |
38
+ -- | 2 | Jade W. | Singing |
39
+ -- | 3 | Victor J. | Singing |
40
+ -- | 4 | Elvis Q. | Eating |
41
+ -- | 5 | Daniel A. | Eating |
42
+ -- | 6 | Bob B. | Horse Riding |
43
+ -- +------+--------------+---------------+
44
+ --
45
+ -- Activities table:
46
+ -- +------+--------------+
47
+ -- | id | name |
48
+ -- +------+--------------+
49
+ -- | 1 | Eating |
50
+ -- | 2 | Singing |
51
+ -- | 3 | Horse Riding |
52
+ -- +------+--------------+
53
+ --
54
+ -- Result table:
55
+ -- +--------------+
56
+ -- | results |
57
+ -- +--------------+
58
+ -- | Singing |
59
+ -- +--------------+
60
+ --
61
+ -- Eating activity is performed by 3 friends, maximum number of participants, (Jonathan D. , Elvis Q. and Daniel A.)
62
+ -- Horse Riding activity is performed by 1 friend, minimum number of participants, (Bob B.)
63
+ -- Singing is performed by 2 friends (Victor J. and Jade W.)
64
+
65
+ -- # Write your MySQL query statement below
66
+ select activityfrom Friendsgroup by activity
67
+ having count (id) notin
68
+ (
69
+ select max (cnt)as cntfrom
70
+ (select count (* )as cntfrom Friendsgroup by activity)as t1
71
+ union
72
+ select min (cnt)as cntfrom
73
+ (select count (* )as cntfrom Friendsgroup by activity)as t2
74
+ )