Bird
0
0

Consider the table employees with columns department, role, and salary. What does this query return?

medium📝 query result Q5 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Consider the table employees with columns department, role, and salary. What does this query return?
SELECT department, role, AVG(salary) FROM employees GROUP BY department, role;
AAverage salary for all employees without grouping
BAverage salary for each department only
CAverage salary for each role only
DAverage salary for each department and role combination
Step-by-Step Solution
Solution:
  1. Step 1: Identify grouping columns

    The query groups by both department and role, so groups are unique pairs of these columns.
  2. Step 2: Understand aggregation

    AVG(salary) calculates average salary per group, here per department-role pair.
  3. Final Answer:

    Average salary for each department and role combination -> Option D
  4. Quick Check:

    GROUP BY multiple columns with AVG = average per combination [OK]
Quick Trick: AVG with GROUP BY multiple columns averages per combo [OK]
Common Mistakes:
  • Assuming grouping by only one column
  • Expecting overall average without grouping
  • Mixing up department and role grouping

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes