Bird
0
0

Identify the error in this query:

medium📝 Debug Q6 of 15
SQL - Window Functions Fundamentals
Identify the error in this query:
SELECT employee_id, salary, SUM(salary) OVER () FROM employees GROUP BY employee_id;
ASUM() cannot be used as a window function.
BCannot use window function with GROUP BY without including all selected columns in GROUP BY.
CMissing ORDER BY clause in window function.
DNo error; query is valid.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze GROUP BY and window function interaction

    When GROUP BY is used, all selected columns except aggregates must be in GROUP BY.
  2. Step 2: Identify missing columns in GROUP BY

    salary is selected but not in GROUP BY, causing error.
  3. Final Answer:

    Cannot use window function with GROUP BY without including all selected columns in GROUP BY. -> Option B
  4. Quick Check:

    GROUP BY columns must match SELECT non-aggregates = B [OK]
Quick Trick: All non-aggregated columns must be in GROUP BY [OK]
Common Mistakes:
  • Ignoring columns missing from GROUP BY
  • Thinking window functions bypass GROUP BY rules
  • Assuming ORDER BY is mandatory in window functions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes