Bird
0
0

Identify the syntax error in this SQL query using a window function:

medium📝 Debug Q7 of 15
SQL - Window Functions Fundamentals
Identify the syntax error in this SQL query using a window function:
SELECT id, amount, RANK() OVER PARTITION BY category ORDER BY amount DESC FROM products;
AMissing parentheses around PARTITION BY and ORDER BY clauses inside OVER()
BRANK() cannot be used with ORDER BY
CPARTITION BY cannot be used without GROUP BY
DORDER BY cannot be used inside OVER()
Step-by-Step Solution
Solution:
  1. Step 1: Review window function syntax

    The OVER clause must enclose partitioning and ordering clauses inside parentheses.
  2. Step 2: Analyze the query

    The query lacks parentheses after OVER keyword: it should be OVER (PARTITION BY category ORDER BY amount DESC).
  3. Step 3: Evaluate options

    Missing parentheses around PARTITION BY and ORDER BY clauses inside OVER() correctly identifies missing parentheses.
    Options B, C, and D are incorrect statements about window functions.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    OVER() must enclose PARTITION BY and ORDER BY [OK]
Quick Trick: Always use parentheses after OVER keyword [OK]
Common Mistakes:
  • Omitting parentheses after OVER
  • Misusing PARTITION BY without parentheses
  • Confusing window functions with GROUP BY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes