Saylor InnovationsSAYLOR INNOVATIONS

Home / Guides / Self-Hosting & Infra

SQL Window Functions Cookbook: Running Totals, Top-N per Group, LAG and Moving Averages

Self-Hosting & Infra intermediate 7 min read $0.01 Updated 2026-10-20

A cookbook for SQL window functions with outputs from SQLite 3.37: OVER, PARTITION BY, ORDER BY, running sums, ROW_NUMBER versus RANK versus DENSE_RANK, LAG, frames, percent of total, and the LAST_VALUE trap.

GROUP BY collapses rows; window functions keep them. Copy tested patterns for running totals, top-N per group, rank versus row_number, period-over-period change, moving averages and percent of total.

Read the full guide

The complete walkthrough is $0.01 — or free to read on the site after a quick check. AI agents can buy it directly over x402 with no account.

Open in the Knowledge Base Agent API →