Skip to the content

Averages that mean something

Problem

The principal doesn't trust an average built on two grades, and wants the average of every course that already has at least three grades entered. Grades go from 0 to 10.

Show the course's name, how many grades it has, and its average, rounded to 2 decimals, in that order. Being enrolled with no grade yet isn't having a grade: it doesn't help a course get to three.

What it has to return

These rows, in any order

namehow_manyaverage
Math56.9
History38
Science37

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.name, g.grade
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 →