📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    Given a table employees(id, dept_id, salary), which

    query returns departments with average salary greater than overall average across the company?
    A SELECT dept_id FROM employees WHERE salary > (SELECT AVG(salary) FROM employees); Correct Answer Incorrect Answer
    B SELECT dept_id FROM employees GROUP BY dept_id HAVING AVG(salary) > (SELECT AVG(salary) FROM employees); Correct Answer Incorrect Answer
    C SELECT dept_id FROM employees GROUP BY dept_id WHERE AVG(salary) > (SELECT AVG(salary) FROM employees); Correct Answer Incorrect Answer
    D SELECT dept_id FROM employees WHERE AVG(salary) > (SELECT AVG(salary) FROM employees) GROUP BY dept_id; Correct Answer Incorrect Answer
    E SELECT dept_id FROM employees GROUP BY dept_id HAVING AVG(salary) > AVG(salary); Correct Answer Incorrect Answer

    Solution

    Use GROUP BY and HAVING to compare group avg to overall avg computed via subquery.

    Practice Next
    ask-question