Write a query to find the students who scored above the average marks

Description: Show the students whose marks are higher than the average marks of all students.

Tables: the exercises use the students (id, name, city, marks, course_id) and courses (id, course_name) tables, with the data from our MySQL INSERT chapter. The students are: Robin (Delhi, 85), Maria (Mumbai, 92), John (Pune, 78), Asha (Jaipur, 88), Vikram (Delhi, 65), Neha (Mumbai, 45).

Hint:

  • The average comes from a subquery: (SELECT AVG(marks) FROM students).

MySQL query for students above the average

SELECT name, marks
FROM students
WHERE marks > (SELECT AVG(marks) FROM students)
ORDER BY marks DESC;

Output:

Tutorials Class - Output Window
name marks
Maria 92
Asha 88
Robin 85
John 78

How it works

  • The average marks are 453 / 6 = 75.5.
  • Four students are above it.

Read Subqueries.


Learn more about the similar topics:
Tutorials
MySQL JOINs
MySQL Subqueries
MySQL UNION
Exercises & Assignments
Write a query to show the student name who has the second highest marks
Write a query to show the names of students with their course names
Write a query to count the students of each course, including empty courses
Write a query to find the students who scored above the average marks
Interview Questions & Answers
What is the difference between INNER JOIN and LEFT JOIN?
What is the difference between UNION and UNION ALL?
What are the types of JOINs in MySQL?
How to find the second highest marks in MySQL?
What is a subquery in MySQL?