Explain the duplicate-peers gotcha that the default RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW frame can cause.

Quick Overview

Asks what goes wrong with a SQL running total when the window uses the default RANGE frame and the ORDER BY key has ties. It tests understanding of peer rows, the difference between RANGE and ROWS frames, deterministic ordering, and related traps such as LAST_VALUE.

Explain the duplicate-peers gotcha that the default RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW frame can cause.

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

Explain the duplicate-peers gotcha that the default `RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW` frame can cause. This is the frame a SQL window function gets when it has an `ORDER BY` but no explicit frame clause, as in a running total written `SUM(amount) OVER (ORDER BY sale_date)`. ```hint Try it on tied rows Take a small table where two rows share the same `sale_date` and work out which rows the frame contains for each of those two rows. ``` ### What a Strong Answer Covers - What "peers" are and how a `RANGE` frame decides where the current row ends - What a running `SUM()` shows on tied rows under the default frame, with a small example - How a `ROWS` frame behaves on the same data - How to make the result deterministic when the ordering key has ties - Which other window functions are affected by the frame and which ignore it ### Follow-up Questions - Why does `LAST_VALUE(x) OVER (ORDER BY d)` often fail to return the last value of the partition, and how do you fix it? - If you switch to `ROWS` but keep `ORDER BY sale_date` alone, is the running total deterministic? What would you add? - When is the `RANGE` behavior on peers what you actually want? - What does the frame default to when the window has no `ORDER BY` at all?

Overview: Asks what goes wrong with a SQL running total when the window uses the default RANGE frame and the ORDER BY key has ties. It tests understanding of peer rows, the difference between RANGE and ROWS frames, deterministic ordering, and related traps such as LAST_VALUE.

General logo
General
Nov 24, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

Explain the duplicate-peers gotcha that the default RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW frame can cause.

This is the frame a SQL window function gets when it has an ORDER BY but no explicit frame clause, as in a running total written SUM(amount) OVER (ORDER BY sale_date).

What a Strong Answer Covers Guidance

  • What "peers" are and how a RANGE frame decides where the current row ends
  • What a running SUM() shows on tied rows under the default frame, with a small example
  • How a ROWS frame behaves on the same data
  • How to make the result deterministic when the ordering key has ties
  • Which other window functions are affected by the frame and which ignore it

Follow-up Questions Guidance

  • Why does LAST_VALUE(x) OVER (ORDER BY d) often fail to return the last value of the partition, and how do you fix it?
  • If you switch to ROWS but keep ORDER BY sale_date alone, is the running total deterministic? What would you add?
  • When is the RANGE behavior on peers what you actually want?
  • What does the frame default to when the window has no ORDER BY at all?