Skip to content

Commit 4e77eb9

Browse files
committed
task: #1280
1 parent c67b5d6 commit 4e77eb9

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Have a good contributing!
5656
- [1148. Article Views I](./leetcode/easy/1148.%20Article%20Views%20I.sql)
5757
- [1211. Queries Quality and Percentage](./leetcode/easy/1211.%20Queries%20Quality%20and%20Percentage.sql)
5858
- [1251. Average Selling Price](./leetcode/easy/1251.%20Average%20Selling%20Price.sql)
59+
- [1280. Students and Examinations](./leetcode/easy/1280.%20Students%20and%20Examinations.sql)
5960
- [1327. List the Products Ordered in a Period](./leetcode/easy/1327.%20List%20the%20Products%20Ordered%20in%20a%20Period.sql)
6061
- [1378. Replace Employee ID With The Unique Identifier](./leetcode/easy/1378.%20Replace%20Employee%20ID%20With%20The%20Unique%20Identifier.sql)
6162
- [1407. Top Travellers](./leetcode/easy/1407.%20Top%20Travellers.sql)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Question 1280. Students and Examinations
3+
Link: https://leetcode.com/problems/students-and-examinations/description/?envType=study-plan-v2&envId=top-sql-50
4+
5+
Table: Students
6+
7+
+---------------+---------+
8+
| Column Name | Type |
9+
+---------------+---------+
10+
| student_id | int |
11+
| student_name | varchar |
12+
+---------------+---------+
13+
student_id is the primary key (column with unique values) for this table.
14+
Each row of this table contains the ID and the name of one student in the school.
15+
16+
17+
Table: Subjects
18+
19+
+--------------+---------+
20+
| Column Name | Type |
21+
+--------------+---------+
22+
| subject_name | varchar |
23+
+--------------+---------+
24+
subject_name is the primary key (column with unique values) for this table.
25+
Each row of this table contains the name of one subject in the school.
26+
27+
28+
Table: Examinations
29+
30+
+--------------+---------+
31+
| Column Name | Type |
32+
+--------------+---------+
33+
| student_id | int |
34+
| subject_name | varchar |
35+
+--------------+---------+
36+
There is no primary key (column with unique values) for this table. It may contain duplicates.
37+
Each student from the Students table takes every course from the Subjects table.
38+
Each row of this table indicates that a student with ID student_id attended the exam of subject_name.
39+
40+
41+
Write a solution to find the number of times each student attended each exam.
42+
43+
Return the result table ordered by student_id and subject_name.
44+
*/
45+
46+
SELECT
47+
st.student_id,
48+
st.student_name,
49+
s.subject_name,
50+
COUNT(e.student_id) AS attended_exams
51+
FROM Students AS st
52+
CROSS JOIN Subjects AS s
53+
LEFT JOIN
54+
Examinations AS e
55+
ON
56+
st.student_id = e.student_id
57+
AND s.subject_name = e.subject_name
58+
GROUP BY st.student_id, st.student_name, s.subject_name
59+
ORDER BY st.student_id, st.student_name, s.subject_name

0 commit comments

Comments
 (0)