SELECT ID, AVG(SALARY) AS \'AVG\', sum (SALARY) AS \'SUM\', F_NAME as \'FIRSTNAM
ID: 3576602 • Letter: S
Question
SELECT ID, AVG(SALARY) AS 'AVG', sum (SALARY) AS 'SUM', F_NAME as 'FIRSTNAME', L_NAME FROM EMPLOYEES GROUP BY ID HAVING L_NAME IS NOT NULL ORDER BY F_NAME, L_NAME This query results in an error. Which of the following statements correctly identifies the reason why? A The ORDER BY clause must use the aliases identified in the SELECT clause. B The HAVING clause must contain all aggregate columns. C The SELECT clause has incorrect use of aliases. D The GROUP BY clause must contain all non-aggregated columns.Explanation / Answer
Answer is D The GROUP BY clause must contain all non aggregated columns
Above query
SELECT ID , AVG(SALARY) AS AVG,
SUM(SALARY) AS SUM,
F_NAME AS FIRSTNAME,
L_NAME FROM EMPLOYESS
GROUP BY ID
HAVING L_NAME IS NOT NULL
ORDER BY F_NAME,L_NAME
We are using two group functions on salary column.so we should specify other columns other than group function
Above should like this
SELECT ID , AVG(SALARY) AS AVG,
SUM(SALARY) AS SUM,
F_NAME AS FIRSTNAME,
L_NAME FROM EMPLOYESS
GROUP BY ID,F_NAME ,L_NAME --Corrected query here F_NAME,L_NAME should add because we did not apply group function for these column so
HAVING L_NAME IS NOT NULL
ORDER BY F_NAME,L_NAME
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.