Is the following query returns the output?

Forums SQLIs the following query returns the output?
Staff asked 3 years ago

SELECT  Subject, AVG (marks)

FROM Students

WHERE AVG(marks) > 70

GROUP BY Subject

Answers (1)

Add Answer
Tabish Rangrej Marked As Accepted
Staff answered 3 years ago

No, this Query will not work. it will throw you an error.
you can not use an aggregate function with a where clause.

if you still want to filter out data whose average makes is greater than 70 then you can use the HAVING clause. as below.

SELECT  Subject, AVG (marks)
FROM Students
GROUP BY Subject
HAVING  AVG(marks) > 70

 

Subscribe

Select Categories