---
# System prepended metadata

title: 1280. Students and Examinations

---

# [1280. Students and Examinations](https://leetcode.com/problems/students-and-examinations/description/?envType=study-plan-v2&envId=top-sql-50)
![image](https://hackmd.io/_uploads/BkDczZspa.png)
![image](https://hackmd.io/_uploads/S16qfZoap.png)
![image](https://hackmd.io/_uploads/r1BszZi6T.png)
![image](https://hackmd.io/_uploads/r1ooGZoaa.png)
這一題要三張表join
因為我們需要a1的id是必須要有的
所以我們left join a3的所有課表

```SQL
# Write your MySQL query statement below
SELECT  a1.student_id , a1.student_name , a2.subject_name ,COUNT(a3.subject_name) AS attended_exams
FROM Students a1 JOIN Subjects a2 
LEFT JOIN Examinations a3 
ON a1.student_id = a3.student_id
AND a2.subject_name = a3.subject_name
GROUP BY a1.student_id,a2.subject_name 
ORDER BY student_id ASC, subject_name ASC

```