32/34
Part 6 of 6 · Follow-upsLearn and do

Without a window function, a self-join counts the same 7 days

A self-join spells out what the frame means:

SELECT d.ordered_on, COUNT(*) AS orders_7d
FROM (SELECT DISTINCT ordered_on FROM orders) AS d
JOIN orders AS o
  ON julianday(o.ordered_on)
     BETWEEN julianday(d.ordered_on) - 6 AND julianday(d.ordered_on)
GROUP BY d.ordered_on
ORDER BY d.ordered_on;
ordered_onorders_7d
2026-03-012
2026-03-023
2026-03-035
2026-03-093
2026-03-102

Same answers as the RANGE frame. The cost is in the join. Each date matches every order in its week, so the work grows with the number of dates times the orders per week. The window sorts once and moves its frame along.

It's a good second route for checking a window query you aren't sure of.

In the editor, write SELF_JOIN_7D: the same 7-day counts, with a self-join.