HAVING clause is used to impose grouping level conditions
WHERE clause is for the row-level results whereas the HAVING clause is for the group-level results
You apply the GROUP BY function with the aggregate functions and get the group-level results then you can apply the HAVING clause to filter out the grouped data.
SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) HAVING condition ORDER BY column_name(s);
Student table with student_name, subject, and marks
The following query will get the average marks of the students.
SELECT student_name, AVG(marks) FROM students GrOUP BY student_name;
If you want to get the list of students whose average is greater than 70 then you can use the HAVING clause.
SELECT student_name, AVG(marks) FROM students GROUP BY student_name HAVING AVG(marks) > 70