Question:

What’s wrong in the following query?

   SELECT subject_code, AVG (marks)
   FROM students
   WHERE AVG(marks) > 75
   GROUP BY subject_code;

Answer:

The WHERE clause cannot be used to restrict groups. The HAVING clause should be used.

   SELECT subject_code, AVG (marks)
   FROM students
   HAVING AVG(marks) > 75
   GROUP BY subject_code;

Keywords:

© 2017 QuizBucket.org