Students and Examinations
<p>Table: <code>Students</code></p>

<pre>
+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| student_id    | int     |
| student_name  | varchar |
+---------------+---------+
student_id is the primary key (column with unique values) for this table.
Each row of this table contains the ID and the name of one student in the school.
</pre>

<p>&nbsp;</p>

<p>Table: <code>Subjects</code></p>

<pre>
+--------------+---------+
| Column Name  | Type    |
+--------------+---------+
| subject_name | varchar |
+--------------+---------+
subject_name is the primary key (column with unique values) for this table.
Each row of this table contains the name of one subject in the school.
</pre>

<p>&nbsp;</p>

<p>Table: <code>Examinations</code></p>

<pre>
+--------------+---------+
| Column Name  | Type    |
+--------------+---------+
| student_id   | int     |
| subject_name | varchar |
+--------------+---------+
There is no primary key (column with unique values) for this table. It may contain duplicates.
Each student from the Students table takes every course from the Subjects table.
Each row of this table indicates that a student with ID student_id attended the exam of subject_name.
</pre>

<p>&nbsp;</p>

<p>Write a solution to find the number of times each student attended each exam.</p>

<p>Return the result table ordered by <code>student_id</code> and <code>subject_name</code>.</p>

<p>The result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> 
Students table:
+------------+--------------+
| student_id | student_name |
+------------+--------------+
| 1          | Alice        |
| 2          | Bob          |
| 13         | John         |
| 6          | Alex         |
+------------+--------------+
Subjects table:
+--------------+
| subject_name |
+--------------+
| Math         |
| Physics      |
| Programming  |
+--------------+
Examinations table:
+------------+--------------+
| student_id | subject_name |
+------------+--------------+
| 1          | Math         |
| 1          | Physics      |
| 1          | Programming  |
| 2          | Programming  |
| 1          | Physics      |
| 1          | Math         |
| 13         | Math         |
| 13         | Programming  |
| 13         | Physics      |
| 2          | Math         |
| 1          | Math         |
+------------+--------------+
<strong>Output:</strong> 
+------------+--------------+--------------+----------------+
| student_id | student_name | subject_name | attended_exams |
+------------+--------------+--------------+----------------+
| 1          | Alice        | Math         | 3              |
| 1          | Alice        | Physics      | 2              |
| 1          | Alice        | Programming  | 1              |
| 2          | Bob          | Math         | 1              |
| 2          | Bob          | Physics      | 0              |
| 2          | Bob          | Programming  | 1              |
| 6          | Alex         | Math         | 0              |
| 6          | Alex         | Physics      | 0              |
| 6          | Alex         | Programming  | 0              |
| 13         | John         | Math         | 1              |
| 13         | John         | Physics      | 1              |
| 13         | John         | Programming  | 1              |
+------------+--------------+--------------+----------------+
<strong>Explanation:</strong> 
The result table should contain all students and all subjects.
Alice attended the Math exam 3 times, the Physics exam 2 times, and the Programming exam 1 time.
Bob attended the Math exam 1 time, the Programming exam 1 time, and did not attend the Physics exam.
Alex did not attend any exams.
John attended the Math exam 1 time, the Physics exam 1 time, and the Programming exam 1 time.
</pre>

[]
['Create table If Not Exists Students (student_id int, student_name varchar(20))', 'Create table If Not Exists Subjects (subject_name varchar(20))', 'Create table If Not Exists Examinations (student_id int, subject_name varchar(20))', 'Truncate table Students', "insert into Students (student_id, student_name) values ('1', 'Alice')", "insert into Students (student_id, student_name) values ('2', 'Bob')", "insert into Students (student_id, student_name) values ('13', 'John')", "insert into Students (student_id, student_name) values ('6', 'Alex')", 'Truncate table Subjects', "insert into Subjects (subject_name) values ('Math')", "insert into Subjects (subject_name) values ('Physics')", "insert into Subjects (subject_name) values ('Programming')", 'Truncate table Examinations', "insert into Examinations (student_id, subject_name) values ('1', 'Math')", "insert into Examinations (student_id, subject_name) values ('1', 'Physics')", "insert into Examinations (student_id, subject_name) values ('1', 'Programming')", "insert into Examinations (student_id, subject_name) values ('2', 'Programming')", "insert into Examinations (student_id, subject_name) values ('1', 'Physics')", "insert into Examinations (student_id, subject_name) values ('1', 'Math')", "insert into Examinations (student_id, subject_name) values ('13', 'Math')", "insert into Examinations (student_id, subject_name) values ('13', 'Programming')", "insert into Examinations (student_id, subject_name) values ('13', 'Physics')", "insert into Examinations (student_id, subject_name) values ('2', 'Math')", "insert into Examinations (student_id, subject_name) values ('1', 'Math')"]
[{"value": "mysql", "text": "MySQL", "defaultCode": "# Write your MySQL query statement below\n"}, {"value": "mssql", "text": "MS SQL Server", "defaultCode": "/* Write your T-SQL query statement below */\n"}, {"value": "oraclesql", "text": "Oracle", "defaultCode": "/* Write your PL/SQL query statement below */\n"}, {"value": "pythondata", "text": "Pandas", "defaultCode": "import pandas as pd\n\ndef students_and_examinations(students: pd.DataFrame, subjects: pd.DataFrame, examinations: pd.DataFrame) -> pd.DataFrame:\n    "}, {"value": "postgresql", "text": "PostgreSQL", "defaultCode": "-- Write your PostgreSQL query statement below\n"}]
{"mysql": ["Create table If Not Exists Students (student_id int, student_name varchar(20))", "Create table If Not Exists Subjects (subject_name varchar(20))", "Create table If Not Exists Examinations (student_id int, subject_name varchar(20))"], "mssql": ["Create table Students (student_id int, student_name varchar(20))", "Create table Subjects (subject_name varchar(20))", "Create table Examinations (student_id int, subject_name varchar(20))"], "oraclesql": ["Create table Students (student_id int, student_name varchar(20))\n", "Create table Subjects (subject_name varchar(20))\n", "Create table Examinations (student_id int, subject_name varchar(20))"], "database": true, "name": "students_and_examinations", "pythondata": ["Students = pd.DataFrame([], columns=['student_id', 'student_name']).astype({'student_id':'Int64', 'student_name':'object'})", "Subjects = pd.DataFrame([], columns=['subject_name']).astype({'subject_name':'object'})", "Examinations = pd.DataFrame([], columns=['student_id', 'subject_name']).astype({'student_id':'Int64', 'subject_name':'object'})"], "manual": false, "postgresql": ["\nCreate table If Not Exists Students (student_id int, student_name varchar(20))\n", "Create table If Not Exists Subjects (subject_name varchar(20))", "Create table If Not Exists Examinations (student_id int, subject_name varchar(20))"], "database_schema": {"Students": {"student_id": "INT", "student_name": "VARCHAR(20)"}, "Subjects": {"subject_name": "VARCHAR(20)"}, "Examinations": {"student_id": "INT", "subject_name": "VARCHAR(20)"}}}
{"mysql": ["MySQL", "<p><code>MySQL 8.0</code>.</p>"], "mssql": ["MS SQL Server", "<p><code>mssql server 2019</code>.</p>"], "oraclesql": ["Oracle", "<p><code>Oracle Sql 11.2</code>.</p>"], "pythondata": ["Pandas", "<p>Python 3.10 with Pandas 2.2.2 and NumPy 1.26.4</p>"], "postgresql": ["PostgreSQL", "<p>PostgreSQL 16</p>"]}
['Database']