Bird
0
0

Find the issue in this SQL query:

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

SELECT country, AVG(age) FROM users;
AQuery should use WHERE instead of SELECT
BAVG() cannot be used with numeric columns
Ccountry should be inside an aggregate function
DMissing GROUP BY clause for the non-aggregated column
Step-by-Step Solution
Solution:
  1. Step 1: Check aggregation rules

    Columns in SELECT must be aggregated or included in GROUP BY.
  2. Step 2: Analyze query

    country is non-aggregated but not in GROUP BY, causing error.
  3. Final Answer:

    Missing GROUP BY clause for the non-aggregated column -> Option D
  4. Quick Check:

    Non-aggregated columns require GROUP BY [OK]
Quick Trick: Non-aggregated columns must be grouped [OK]
Common Mistakes:
MISTAKES
  • Omitting GROUP BY when mixing aggregates and columns
  • Assuming AVG() only works on integers
  • Trying to aggregate non-numeric columns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes