SQL Query Errors and Troubleshooting

Why the following statement is erroneous? SELECT dept_name, ID, avg (salary) FROM instructor GROUP BY dept_name;

Answer: Dept_id should not be used in group by clause
Explanation
  • The correct answer is: Dept_id should not be used in group by clause (although this is not the case in the given query, as it uses dept_name)
  • The error in the statement is that the ID column is not included in the GROUP BY clause. When using an aggregate function like AVG, all non-aggregated columns in the SELECT clause must be included in the GROUP BY clause.
This question appeared in Past Papers (2 times)
Secondary School Teacher SST Past Papers, Syllabus, Jobs (1 times)
This question appeared in Subjects (1 times)

Install this app on your device for quick access right from your home screen.