A window function performs a calculation across a set of rows and returns a value for each row, without collapsing anything, which is exactly what GROUP BY cannot do. This cheatsheet gathers the whole toolkit on one page, from the OVER clause and PARTITION BY through running totals, ranking, LAG and LEAD, frames, and NTILE, each snippet annotated line by line. Keep it open while you write SQL, or save the image and pin it nearby.
For the full background, read the guide to window functions in BigQuery. To practise, work through the 10 code-along examples.
Download the cheatsheet
Hope this helps.
[…] Window Functions in BigQuery Cheatsheet […]
[…] Cheatsheet: https://datalad.co.uk/window-functions-in-bigquery-cheatsheet/ […]