I am doing some study for work on SQL queries.
I came across the following on TutorialsPoint and I'm confused as to why the answer is B and not C.
I have always been told that the GROUP BY Clause comes before HAVING and that HAVING always comes at the end. There is also a lot of documentation online to support my solution, for example: http://www.dba-oracle.com/t_oracle_group_by_having.htm and SQL query, sequence of execution
Can anyone tell me why B is correct in the following example and not C. The tutorial gives B as correct.
Consider the following schema-
STUDENTS(
student_code, first_name, last_name,
email, phone_no, date_of_birth,
honours_subject, percentage_of_marks
);
Which of the following query will correctly list the average percentage of marks in each honours subject, when the average is more than 50 percent?
B.
select honours_subject,
avg(percentage_of_marks)
from students
having avg(percentage_of_marks) > 50.0
group by honours_subject;
C.
select honours_subject,
avg(percentage_of_marks)
from students
group by honours_subject
having avg(percentage_of_marks) > 50.0;