0
0
PostgreSQLquery~5 mins

Window frame (ROWS BETWEEN, RANGE BETWEEN) in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the ROWS BETWEEN clause specify in a window function?
It defines the frame of rows relative to the current row by counting physical rows before and after it.
Click to reveal answer
intermediate
How does RANGE BETWEEN differ from ROWS BETWEEN in window frames?
RANGE BETWEEN defines the frame based on logical values of the ORDER BY column, including all rows with the same value, while ROWS BETWEEN counts physical rows.
Click to reveal answer
beginner
What is the default window frame if none is specified?
The default is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, meaning from the first row with the same ORDER BY value up to the current row.
Click to reveal answer
beginner
Explain the effect of ROWS BETWEEN 2 PRECEDING AND CURRENT ROW in a window function.
It includes the current row and the two rows before it in the frame for calculation.
Click to reveal answer
intermediate
Why might RANGE BETWEEN cause unexpected results with non-unique ORDER BY values?
Because it includes all rows with the same ORDER BY value, the frame can be larger than expected, affecting aggregates.
Click to reveal answer
What does ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW mean?
AFrom two rows before to two rows after the current row
BFrom the current row to the last row in the partition
COnly the current row
DFrom the first row in the partition to the current row
Which window frame clause counts physical rows relative to the current row?
ARANGE BETWEEN
BROWS BETWEEN
CGROUPS BETWEEN
DPARTITION BY
If ORDER BY column has duplicates, which frame clause includes all rows with the same value?
ARANGE BETWEEN
BPARTITION BY
CROWS BETWEEN
DORDER BY
What is the default frame when using window functions with ORDER BY but no frame clause?
ARANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
BNo frame is applied
CROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
DROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
Which clause would you use to include exactly 3 rows before and the current row in a window frame?
ARANGE BETWEEN 3 PRECEDING AND CURRENT ROW
BROWS BETWEEN CURRENT ROW AND 3 FOLLOWING
CROWS BETWEEN 3 PRECEDING AND CURRENT ROW
DRANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
Describe the difference between ROWS BETWEEN and RANGE BETWEEN in window frames.
Think about counting rows versus counting values.
You got /4 concepts.
    Explain why the default window frame is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW and what it means for aggregate calculations.
    Consider how cumulative sums or averages work.
    You got /4 concepts.