Bird
0
0

Consider this query:

medium📝 Debug Q14 of 15
PostgreSQL - Window Functions in PostgreSQL
Consider this query:
SELECT name, salary, SUM(salary) OVER w
FROM employees
WINDOW w AS (PARTITION BY department ORDER BY name BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW);

It returns an error. What is the likely cause?
AThe window frame clause requires ROWS or RANGE keyword explicitly
BThe window frame clause is invalid without RANGE keyword
CThe WINDOW clause must come after ORDER BY clause
DThe window name cannot be used in the OVER clause
Step-by-Step Solution
Solution:
  1. Step 1: Check window frame syntax

    The frame clause must specify ROWS or RANGE explicitly before frame boundaries.
  2. Step 2: Identify error cause

    The query has ORDER BY name BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, missing the required ROWS or RANGE keyword before BETWEEN.
  3. Final Answer:

    The window frame clause requires ROWS or RANGE keyword explicitly -> Option A
  4. Quick Check:

    Window frame needs ROWS or RANGE keyword [OK]
Quick Trick: Always specify ROWS or RANGE in window frame [OK]
Common Mistakes:
  • Placing WINDOW clause after ORDER BY
  • Omitting ROWS or RANGE keyword
  • Using window name incorrectly in OVER

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes