All topics / SQL Window Functions

SQL Window Functions

The analyst superpower: running totals, rankings, and row-to-row comparisons without collapsing rows. OVER, PARTITION BY, and lag and lead.

  1. The window, not the group
  2. OVER, PARTITION BY, ORDER BY
  3. Frames, moving averages, and top-N-per-group