Derived Tables
Subquery as a table.
sql
1SELECT avg_by_course.course, avg_by_course.avg
2FROM (
3 SELECT course, AVG(marks) AS avg
4 FROM students GROUP BY course
5) AS avg_by_course
6WHERE avg_by_course.avg > 75;
Subquery as a table.
1SELECT avg_by_course.course, avg_by_course.avg
2FROM (
3 SELECT course, AVG(marks) AS avg
4 FROM students GROUP BY course
5) AS avg_by_course
6WHERE avg_by_course.avg > 75;