Student Report Pivot

ASKED IN INTERVIEW
4pts
Ed Tech

Problem Statement

Create a report showing Math, Science, and English scores as columns for every student.

Rules:

  • Output columns: student_id, student_name, math_score, science_score, english_score.
  • Missing scores must be 0.
  • Sort by student_id ASC.
Tests your understanding of
Pivot, CASE WHEN, Aggregation and Joins

Input Tables

students
student_id(INTEGER)student_name(VARCHAR)
1Alice
2Bob
grades
student_id(INTEGER)subject_name(VARCHAR)score(INTEGER)
1Math95
1Science88
2Math70
2English85
subjects
subject_id(INTEGER)subject_name(VARCHAR)
101Math

Expected Output

student_id(INTEGER)student_name(VARCHAR)math_score(INTEGER)science_score(INTEGER)english_score(INTEGER)
1Alice95880
2Bob70085

Tags

MediumASKED IN INTERVIEWPivotCASE WHENAggregationJoins
20-30 min
58%

Hints