Bird
0
0

Identify the error in this query:

medium📝 Debug Q6 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Identify the error in this query:
SELECT department, AVG(salary) FROM employees GROUP BY role;
AGrouping column does not match selected non-aggregated column
BAVG() cannot be used with GROUP BY
CMissing WHERE clause for filtering
DGROUP BY must include all columns in the table
Step-by-Step Solution
Solution:
  1. Step 1: Check selected columns vs GROUP BY

    Selected non-aggregated column is department, but grouping is by role, causing mismatch.
  2. Step 2: Understand GROUP BY rules

    All selected columns that are not aggregated must appear in GROUP BY clause.
  3. Final Answer:

    Grouping column does not match selected non-aggregated column -> Option A
  4. Quick Check:

    GROUP BY columns must match non-aggregated SELECT columns [OK]
Quick Trick: Non-aggregated SELECT columns must be in GROUP BY [OK]
Common Mistakes:
  • Grouping by different column than selected
  • Thinking AVG disallows GROUP BY
  • Believing WHERE is required for GROUP BY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes