Skip to content

Commit 23e5bc8

Browse files
author
Shuo
committed
Add: desc
1 parent 01e0aa5 commit 23e5bc8

File tree

3 files changed

+223
-0
lines changed

3 files changed

+223
-0
lines changed

problems/activity-participants/README.md

+64
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,68 @@
1111

1212
## [1355. Activity Participants (Medium)](https://leetcode.com/problems/activity-participants "")
1313

14+
<p>Table: <code>Friends</code></p>
15+
<pre>
16+
+---------------+---------+
17+
| Column Name | Type |
18+
+---------------+---------+
19+
| id | int |
20+
| name | varchar |
21+
| activity | varchar |
22+
+---------------+---------+
23+
id is the id of the friend and primary key for this table.
24+
name is the name of the friend.
25+
activity is the name of the activity which the friend takes part in.
26+
</pre>
1427

28+
<p>Table: <code>Activities</code></p>
29+
<pre>
30+
+---------------+---------+
31+
| Column Name | Type |
32+
+---------------+---------+
33+
| id | int |
34+
| name | varchar |
35+
+---------------+---------+
36+
id is the primary key for this table.
37+
name is the name of the activity.
38+
</pre>
39+
40+
Write an SQL query to find the names of all the activities with neither maximum, nor minimum number of participants.
41+
42+
Return the result table in any order. Each activity in table Activities is performed by any person in the table Friends.
43+
44+
The query result format is in the following example:
45+
46+
Friends table:
47+
<pre>
48+
+------+--------------+---------------+
49+
| id | name | activity |
50+
+------+--------------+---------------+
51+
| 1 | Jonathan D. | Eating |
52+
| 2 | Jade W. | Singing |
53+
| 3 | Victor J. | Singing |
54+
| 4 | Elvis Q. | Eating |
55+
| 5 | Daniel A. | Eating |
56+
| 6 | Bob B. | Horse Riding |
57+
+------+--------------+---------------+
58+
59+
Activities table:
60+
+------+--------------+
61+
| id | name |
62+
+------+--------------+
63+
| 1 | Eating |
64+
| 2 | Singing |
65+
| 3 | Horse Riding |
66+
+------+--------------+
67+
68+
Result table:
69+
+--------------+
70+
| results |
71+
+--------------+
72+
| Singing |
73+
+--------------+
74+
75+
Eating activity is performed by 3 friends, maximum number of participants, (Jonathan D. , Elvis Q. and Daniel A.)
76+
Horse Riding activity is performed by 1 friend, minimum number of participants, (Bob B.)
77+
Singing is performed by 2 friends (Victor J. and Jade W.)
78+
</pre>

problems/movie-rating/README.md

+92
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,96 @@
1111

1212
## [1341. Movie Rating (Medium)](https://leetcode.com/problems/movie-rating "电影评分")
1313

14+
<p>Table: <code>Movies</code></p>
15+
<pre>
16+
+---------------+---------+
17+
| Column Name | Type |
18+
+---------------+---------+
19+
| movie_id | int |
20+
| title | varchar |
21+
+---------------+---------+
22+
movie_id is the primary key for this table.
23+
title is the name of the movie.
24+
</pre>
1425

26+
<p>Table: <code>Users</code></p>
27+
<pre>
28+
+---------------+---------+
29+
| Column Name | Type |
30+
+---------------+---------+
31+
| user_id | int |
32+
| name | varchar |
33+
+---------------+---------+
34+
user_id is the primary key for this table.
35+
</pre>
36+
37+
<p>Table: <code>Movie_Rating</code></p>
38+
<pre>
39+
+---------------+---------+
40+
| Column Name | Type |
41+
+---------------+---------+
42+
| movie_id | int |
43+
| user_id | int |
44+
| rating | int |
45+
| created_at | date |
46+
+---------------+---------+
47+
(movie_id, user_id) is the primary key for this table.
48+
This table contains the rating of a movie by a user in their review.
49+
created_at is the user's review date.
50+
</pre>
51+
52+
Write the following SQL query:
53+
54+
- Find the name of the user who has rated the greatest number of the movies.
55+
In case of a tie, return lexicographically smaller user name.
56+
57+
- Find the movie name with the highest average rating as of Feb 2020.
58+
In case of a tie, return lexicographically smaller movie name..
59+
60+
Query is returned in 2 rows, the query result format is in the folowing example:
61+
<pre>
62+
Movie table:
63+
+-------------+--------------+
64+
| movie_id | title |
65+
+-------------+--------------+
66+
| 1 | Avengers |
67+
| 2 | Frozen 2 |
68+
| 3 | Joker |
69+
+-------------+--------------+
70+
71+
Users table:
72+
+-------------+--------------+
73+
| user_id | name |
74+
+-------------+--------------+
75+
| 1 | Daniel |
76+
| 2 | Monica |
77+
| 3 | Maria |
78+
| 4 | James |
79+
+-------------+--------------+
80+
81+
Movie_Rating table:
82+
+-------------+--------------+--------------+-------------+
83+
| movie_id | user_id | rating | created_at |
84+
+-------------+--------------+--------------+-------------+
85+
| 1 | 1 | 3 | 2020-01-12 |
86+
| 1 | 2 | 4 | 2020-02-11 |
87+
| 1 | 3 | 2 | 2020-02-12 |
88+
| 1 | 4 | 1 | 2020-01-01 |
89+
| 2 | 1 | 5 | 2020-02-17 |
90+
| 2 | 2 | 2 | 2020-02-01 |
91+
| 2 | 3 | 2 | 2020-03-01 |
92+
| 3 | 1 | 3 | 2020-02-22 |
93+
| 3 | 2 | 4 | 2020-02-25 |
94+
+-------------+--------------+--------------+-------------+
95+
96+
Result table:
97+
+--------------+
98+
| results |
99+
+--------------+
100+
| Daniel |
101+
| Frozen 2 |
102+
+--------------+
103+
104+
Daniel and Maria have rated 3 movies ("Avengers", "Frozen 2" and "Joker") but Daniel is smaller lexicographically.
105+
Frozen 2 and Joker have a rating average of 3.5 in February but Frozen 2 is smaller lexicographically.
106+
</pre>

problems/students-with-invalid-departments/README.md

+67
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,71 @@
1111

1212
## [1350. Students With Invalid Departments (Easy)](https://leetcode.com/problems/students-with-invalid-departments "院系无效的学生")
1313

14+
<p>Table: <code>Departments</code></p>
15+
<pre>
16+
+---------------+---------+
17+
| Column Name | Type |
18+
+---------------+---------+
19+
| id | int |
20+
| name | varchar |
21+
+---------------+---------+
22+
id is the primary key of this table.
23+
The table has information about the id of each department of a university.
24+
</pre>
25+
26+
<p>Table: <code>Students</code></p>
27+
<pre>
28+
+---------------+---------+
29+
| Column Name | Type |
30+
+---------------+---------+
31+
| id | int |
32+
| name | varchar |
33+
| department_id | int |
34+
+---------------+---------+
35+
id is the primary key of this table.
36+
The table has information about the id of each student at a university and the id of the department he/she studies at.
37+
</pre>
38+
39+
Write an SQL query to find the id and the name of all students who are enrolled in departments that no longer exists.
1440

41+
Return the result table in any order.
42+
43+
The query result format is in the following example:
44+
<pre>
45+
Departments table:
46+
+------+--------------------------+
47+
| id | name |
48+
+------+--------------------------+
49+
| 1 | Electrical Engineering |
50+
| 7 | Computer Engineering |
51+
| 13 | Bussiness Administration |
52+
+------+--------------------------+
53+
54+
Students table:
55+
+------+----------+---------------+
56+
| id | name | department_id |
57+
+------+----------+---------------+
58+
| 23 | Alice | 1 |
59+
| 1 | Bob | 7 |
60+
| 5 | Jennifer | 13 |
61+
| 2 | John | 14 |
62+
| 4 | Jasmine | 77 |
63+
| 3 | Steve | 74 |
64+
| 6 | Luis | 1 |
65+
| 8 | Jonathan | 7 |
66+
| 7 | Daiana | 33 |
67+
| 11 | Madelynn | 1 |
68+
+------+----------+---------------+
69+
70+
Result table:
71+
+------+----------+
72+
| id | name |
73+
+------+----------+
74+
| 2 | John |
75+
| 7 | Daiana |
76+
| 4 | Jasmine |
77+
| 3 | Steve |
78+
+------+----------+
79+
80+
John, Daiana, Steve and Jasmine are enrolled in departments 14, 33, 74 and 77 respectively. department 14, 33, 74 and 77 doesn't exist in the Departments table.
81+
</pre>

0 commit comments

Comments
 (0)