single
Challenge: Searching for the Top Math Students
Swipe to show menu
The school is pleased with your work and agrees to continue the collaboration.
Now they have a new task for you. 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 you need to do using our employee table as an example.
Suppose you 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, you can use the following query:
1234SELECT department, AVG(salary) AS average_salary FROM employees WHERE hire_date < '2019-01-01' GROUP BY department
As you can see, there are only 3 such employees, and we used the necessary tools to achieve this result.
Swipe to start coding
Retrieve up to 10 students who have scored at least 90 in at least one mathematics exam. For those students, calculate the average of their grades in Mathematics only. Sort the results by this average (alias it as average_grade) in descending order.
Brief Instructions
- Select
student_surnameand the average of thegradecolumn using theAVG()function. - Assign the alias
average_gradeto the second column. - First, determine which students have at least one mathematics grade ≥ 90.
- Include only Mathematics grades when calculating the average.
- Group the results by
student_surname. - Sort the results by
average_gradein descending order. - Use
LIMIT 10to return only 10 results.
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat