I just had this interview question that I couldn't answer. What is wrong with this query in SQL?
SELECT subject_code, AVG (marks)
FROM students
WHERE AVG(marks) > 75
GROUP BY subject_code;
I just had this interview question that I couldn't answer. What is wrong with this query in SQL?
SELECT subject_code, AVG (marks)
FROM students
WHERE AVG(marks) > 75
GROUP BY subject_code;
I think that you need a having clause if you are trying to apply an aggregate into logic.
So the correct answer would be the query should look like
SELECT subject_code,
AVG (marks)
FROM students
GROUP BY subject_code
HAVING AVG(marks) > 75