Bird
0
0

Why does this query cause an error?

medium📝 Debug Q7 of 15
SQL - GROUP BY and HAVING
Why does this query cause an error?

SELECT customer_id, order_date, COUNT(*) FROM orders GROUP BY customer_id;
AGROUP BY must include all columns in SELECT
Bcustomer_id cannot be grouped
Corder_date is neither grouped nor aggregated
DCOUNT(*) cannot be used with GROUP BY
Step-by-Step Solution
Solution:
  1. Step 1: Review SELECT and GROUP BY columns

    Columns in SELECT must be grouped or aggregated when GROUP BY is used.
  2. Step 2: Identify problem

    order_date is selected but not grouped or aggregated, causing an error.
  3. Final Answer:

    order_date is neither grouped nor aggregated -> Option C
  4. Quick Check:

    Non-aggregated column error = D [OK]
Quick Trick: Non-grouped columns must be aggregated [OK]
Common Mistakes:
MISTAKES
  • Thinking COUNT(*) is invalid with GROUP BY
  • Assuming all columns must be in GROUP BY
  • Believing customer_id cannot be grouped

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes