← Back to miito.dev

Digital Garden

October 21
Garden HubAutomotiveTypeScriptTestingSVGSQLSecurityReactPerformanceNode.jsModdingJavaScriptGame DevDevOpsDesignCSSCommunication
miito.dev
© Brian Dinh (miito.dev)
✕
✕
§ GARDEN · SQL · CLASS OPEN
NODE FILE · ENTRY

SQL Window Functions Explained

FILED UNDER · SQL
①Read
②Meta

ROW_NUMBER, RANK, LAG, and LEAD — performing calculations across rows without collapsing them with GROUP BY.

Window functions are the most powerful feature most developers never learn. They let you perform calculations across a set of rows related to the current row — without collapsing those rows into a single result like GROUP BY does. You keep every row and add computed columns alongside them.

The OVER Clause

Every window function uses OVER() to define its window. PARTITION BY groups rows into partitions (like GROUP BY but without collapsing). ORDER BY defines the sequence within each partition. Together they let you rank rows, calculate running totals, compare adjacent rows, and find gaps in sequences.

DTNRWORKSHOP ARMAMENTSSN 2012.OTT.0176