ROWS counts rows, and RANGE measures the ORDER BY value
A frame has a unit and two ends. The unit decides what PRECEDING and FOLLOWING count:
- ROWS counts rows.
6 PRECEDINGreaches back six rows, whatever dates they hold. - RANGE measures the ORDER BY value.
6 PRECEDINGreaches back to every row whose value is at most 6 below the current row's. - GROUPS counts peer groups.
1 PRECEDINGreaches back one group, so the frame holds the current row's peers and the set of peers just before them.
Here's the difference made visible. The query counts orders per date. Then for each date it sums the counts inside each frame, and lists which days of March the frame holds, with group_concat:
WITH daily AS (
SELECT ordered_on, COUNT(*) AS n
FROM orders
GROUP BY ordered_on
)
SELECT ordered_on, n,
group_concat(substr(ordered_on, 9), ' ') OVER by_rows AS rows_frame,
SUM(n) OVER by_rows AS rows_sum,
group_concat(substr(ordered_on, 9), ' ') OVER by_days AS range_frame,
SUM(n) OVER by_days AS range_sum
FROM daily
WINDOW by_rows AS (ORDER BY julianday(ordered_on)
ROWS BETWEEN 6 PRECEDING AND CURRENT ROW),
by_days AS (ORDER BY julianday(ordered_on)
RANGE BETWEEN 6 PRECEDING AND CURRENT ROW)
ORDER BY ordered_on;
| ordered_on | n | rows_frame | rows_sum | range_frame | range_sum |
|---|---|---|---|---|---|
| 2026-03-01 | 2 | 01 | 2 | 01 | 2 |
| 2026-03-02 | 1 | 01 02 | 3 | 01 02 | 3 |
| 2026-03-03 | 2 | 01 02 03 | 5 | 01 02 03 | 5 |
| 2026-03-09 | 1 | 01 02 03 09 | 6 | 03 09 | 3 |
| 2026-03-10 | 1 | 01 02 03 09 10 | 7 | 09 10 | 2 |
Through March 3 they agree, because the first three dates are consecutive. March 9 is where they split. On a calendar:
The dashed lines mark the days that have a row.
The ROWS frame reaches back to March 1. It holds the current row and up to six before it, and only three rows come before it. The RANGE frame stops at March 3, six days back.
With gaps between dates, ROWS covers more than a week. With several rows per date, it covers less. Only RANGE over a day number means the last 7 days.
In the editor, write LAST_THREE_DATES: a ROWS frame on purpose, the orders over the last three dates that had any.