Skip to the content

Chairs for parents' night

Problem

It's parents' night, and each teacher hosts the families of their own students. A teacher sets out one chair per student and hands over one progress report for each course that student takes with them: the family of a student who takes both of a teacher's courses gets one chair and two reports.

For each teacher with students enrolled, show the teacher's name, how many chairs to set out, and how many reports to hand over, in that order. Being enrolled is enough: when a grade is still pending, the report goes out with the grade left blank.

Whoever sets out the most chairs goes first; ties go alphabetically.

What it has to return

These rows, in this order

teacherchairsreports
Rose69
Paul33
Irene22

This is what comes out with the data in the practice database this challenge uses. The column names don’t count, so name yours however you like: what counts is how many there are and the order they come in. Besides this one, the challenge has hidden tests with other data that are revealed when you submit your solution.

You start with this

SQL

SELECT c.teacher, g.student_id
FROM grades g
JOIN courses c
  ON g.course_id = c.id
Solve this challenge

It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.

More O(n) challenges

See all challenges →