Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Searching for the Top Math Students Challenge | Grouping
Intermediate SQL

bookSearching for the Top Math Students Challenge

The school is pleased with our work and agrees to continue the collaboration.

Now they have a new task for us. The top 10 students with the highest average grades will be offered a trip to a scientific center as a reward. One mandatory condition is receiving a grade above 90 on the math exam. To find such students, they have turned to you.

Let's see what we need to do using our employee table as an example.

Suppose we need to find out in which departments there are employees who were hired before 2019 and the average salary in those departments. To implement such a task, we can use the following query:

1234
SELECT department, AVG(salary) AS average_salary FROM employees WHERE hire_date < '2019-01-01' GROUP BY department
copy

As you can see, there are only 3 such employees, and we used the necessary tools to achieve this result.

Task

Swipe to start coding

Retrieve up to 10 students who have scored at least 90 in at least one mathematics exam. For these students, calculate the average of all their mathematics grades. Sort the results by this average (alias it as average_grade) in descending order.

Brief Instructions

  • Select student_surname and the average of the grade column using the AVG() function.
  • Assign the alias average_grade to the second column.
  • First, determine which students have at least one mathematics grade β‰₯ 90.
  • Include all mathematics grades of those students when calculating the average.
  • Group the results by student_surname.
  • Sort the results by average_grade in descending order.
  • Use LIMIT 10 to return only 10 results.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 5
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

Awesome!

Completion rate improved to 4

bookSearching for the Top Math Students Challenge

Swipe to show menu

The school is pleased with our work and agrees to continue the collaboration.

Now they have a new task for us. The top 10 students with the highest average grades will be offered a trip to a scientific center as a reward. One mandatory condition is receiving a grade above 90 on the math exam. To find such students, they have turned to you.

Let's see what we need to do using our employee table as an example.

Suppose we need to find out in which departments there are employees who were hired before 2019 and the average salary in those departments. To implement such a task, we can use the following query:

1234
SELECT department, AVG(salary) AS average_salary FROM employees WHERE hire_date < '2019-01-01' GROUP BY department
copy

As you can see, there are only 3 such employees, and we used the necessary tools to achieve this result.

Task

Swipe to start coding

Retrieve up to 10 students who have scored at least 90 in at least one mathematics exam. For these students, calculate the average of all their mathematics grades. Sort the results by this average (alias it as average_grade) in descending order.

Brief Instructions

  • Select student_surname and the average of the grade column using the AVG() function.
  • Assign the alias average_grade to the second column.
  • First, determine which students have at least one mathematics grade β‰₯ 90.
  • Include all mathematics grades of those students when calculating the average.
  • Group the results by student_surname.
  • Sort the results by average_grade in descending order.
  • Use LIMIT 10 to return only 10 results.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

close

Awesome!

Completion rate improved to 4
SectionΒ 1. ChapterΒ 5
single

single

some-alt