Skip to content

Commit 0a82f1e

Browse files
add 1355
1 parent e15daaf commit 0a82f1e

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ _If you like this project, please leave me a star._ ★
909909

910910
| # | Title | Solutions | Video | Difficulty | Tag
911911
|-----|----------------|---------------|---------------|---------------|-------------
912+
|1355|[Activity Participants](https://leetcode.com/problems/activity-participants/)|[Solution](../master/database/_1355.sql) || Medium |
912913
|1350|[Students With Invalid Departments](https://leetcode.com/problems/students-with-invalid-departments/)|[Solution](../master/database/_1350.sql) || Easy |
913914
|1341|[Movie Rating](https://leetcode.com/problems/movie-rating/)|[Solution](../master/database/_1341.sql) || Medium |
914915
|1327|[List the Products Ordered in a Period](https://leetcode.com/problems/list-the-products-ordered-in-a-period/)|[Solution](../master/database/_1327.sql) || Easy |

database/_1355.sql

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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 activity from Friends group by activity
67+
having count(id) not in
68+
(
69+
select max(cnt) as cnt from
70+
(select count(*) as cnt from Friends group by activity) as t1
71+
union
72+
select min(cnt) as cnt from
73+
(select count(*) as cnt from Friends group by activity) as t2
74+
)

0 commit comments

Comments
 (0)