Computer SPSC
Why the following statement is erroneous? SELECT dept_name, ID, avg (salary) FROM instructor GROUP BY dept_name;
Show answer
Correct answer: A) Dept_id should not be used in group by clause
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.
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.