Recall & Review
beginner
What does the
ROWS BETWEEN clause specify in a window function?It defines the subset of rows (the frame) around the current row to include when calculating the window function.
Click to reveal answer
intermediate
Explain the difference between
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW and ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING.UNBOUNDED PRECEDING AND CURRENT ROW includes all rows from the start of the partition up to the current row.<br>1 PRECEDING AND 1 FOLLOWING includes only the row before, the current row, and the row after.
Click to reveal answer
intermediate
What happens if you omit the
ROWS BETWEEN clause in a window function?The default frame is
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, which may behave differently especially with duplicate values.Click to reveal answer
beginner
Can
ROWS BETWEEN frame include future rows relative to the current row?Yes, by using
FOLLOWING you can include rows after the current row in the frame.Click to reveal answer
beginner
Write a simple SQL query using
ROWS BETWEEN 2 PRECEDING AND CURRENT ROW to calculate a moving sum.SELECT date, sales, SUM(sales) OVER (ORDER BY date ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS moving_sum FROM sales_table;
Click to reveal answer
What does
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW mean?✗ Incorrect
This frame includes all rows from the beginning of the partition until the current row.
Which keyword specifies rows after the current row in a window frame?
✗ Incorrect
FOLLOWING means rows after the current row.If you want to include only the current row and the one before it, which frame would you use?
✗ Incorrect
This frame includes the row before and the current row.
What is the default frame if
ROWS BETWEEN is not specified?✗ Incorrect
The default frame uses RANGE mode from the start of the partition to the current row.
Which of these is a valid frame clause?
✗ Incorrect
Frames must specify a start before the end; 1 PRECEDING to 2 FOLLOWING is valid.
Describe how the
ROWS BETWEEN clause controls which rows are included in a window function calculation.Think about how you select a group of rows around the current row.
You got /4 concepts.
Explain the difference between
ROWS and RANGE in window frame specifications.Consider how duplicates and ordering affect the frame.
You got /4 concepts.