Bird
0
0

What is wrong with this query?

medium📝 Debug Q14 of 15
PostgreSQL - Aggregate Functions and GROUP BY
What is wrong with this query?
SELECT customer_id, COUNT(*) FROM orders;
Acustomer_id must be inside COUNT()
BCOUNT(*) cannot be used without WHERE
CMissing GROUP BY clause for customer_id
DSELECT must have ORDER BY with COUNT
Step-by-Step Solution
Solution:
  1. Step 1: Check aggregation with non-aggregated column

    customer_id is selected but not aggregated or grouped.
  2. Step 2: Identify missing GROUP BY

    To use COUNT(*) with customer_id, GROUP BY customer_id is required.
  3. Final Answer:

    Missing GROUP BY clause for customer_id -> Option C
  4. Quick Check:

    Non-aggregated columns need GROUP BY [OK]
Quick Trick: Use GROUP BY when mixing columns with aggregation [OK]
Common Mistakes:
  • Forgetting GROUP BY when selecting non-aggregated columns
  • Thinking COUNT needs WHERE clause
  • Assuming ORDER BY is mandatory with aggregation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes