Bird
0
0

Find the issue in this SQL statement:

medium📝 Debug Q7 of 15
SQL - GROUP BY and HAVING
Find the issue in this SQL statement:

SELECT city, state, AVG(sales) FROM sales_data GROUP BY city;
Acity should not be in GROUP BY
Bstate is missing from GROUP BY clause
CAVG cannot be used with GROUP BY
DNo issue, query is valid
Step-by-Step Solution
Solution:
  1. Step 1: Compare SELECT and GROUP BY columns

    SELECT includes city and state, but GROUP BY only has city.
  2. Step 2: Recall GROUP BY requirements

    All non-aggregated columns in SELECT must be in GROUP BY to avoid errors.
  3. Final Answer:

    state is missing from GROUP BY clause -> Option B
  4. Quick Check:

    All non-aggregated SELECT columns must be grouped [OK]
Quick Trick: Match all non-aggregated SELECT columns in GROUP BY [OK]
Common Mistakes:
MISTAKES
  • Leaving out columns from GROUP BY
  • Misunderstanding aggregate functions
  • Assuming partial grouping is allowed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes