Who owes grades?
- O(n) · Medium
- Full plan
- SQL
- grouping
- joins
- nulls
Problem
The school secretary wants to know which teachers need a reminder that there are grades to enter. For each teacher with students enrolled, show the teacher's name, how many grades they've already entered, and how many are still pending, in that order.
Some teachers teach more than one course: each shows up once, with all their courses added together. Grades go from 0 to 10, so a zero is a grade that's been entered, not one that's pending.
What it has to return
These rows, in any order
| teacher | entered | pending |
|---|---|---|
| Irene | 2 | 0 |
| Paul | 3 | 0 |
| Rose | 8 | 1 |
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, COUNT(*)
FROM grades g
JOIN courses c
ON g.course_id = c.id
GROUP BY c.teacherIt 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
- A two-credit 10SQL · grouping · joins · decimals
- Aisle by aisleSQL · grouping · conditionals
- Averages that mean somethingSQL · grouping · joins
- Bunched up or spread outSQL · grouping · joins · sorting
- Chairs for parents' nightSQL · grouping · joins · sorting
- How many payrolls does it cover?SQL · grouping · joins · decimals