Bird
0
0

Identify the error in this SQL query:

medium📝 Debug Q14 of 15
SQL - Window Functions Fundamentals
Identify the error in this SQL query:
SELECT employee_id, department, SUM(salary) OVER PARTITION BY department FROM employees;
Adepartment column cannot be used in PARTITION BY.
BSUM() cannot be used with OVER clause.
CMissing parentheses around PARTITION BY clause inside OVER.
Demployee_id must be included in PARTITION BY.
Step-by-Step Solution
Solution:
  1. Step 1: Check OVER clause syntax

    The OVER clause must have parentheses enclosing PARTITION BY and other clauses.
  2. Step 2: Identify missing parentheses

    The query misses parentheses after OVER, it should be OVER (PARTITION BY department).
  3. Final Answer:

    Missing parentheses around PARTITION BY clause inside OVER. -> Option C
  4. Quick Check:

    OVER requires parentheses around PARTITION BY [OK]
Quick Trick: Always put parentheses after OVER, even if only PARTITION BY used [OK]
Common Mistakes:
  • Omitting parentheses after OVER
  • Using aggregate without OVER for window function
  • Including wrong columns in PARTITION BY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes