Window Functions in BigQuery Cheatsheet

A one-page BigQuery window functions reference, every snippet explained line by line: OVER and PARTITION BY, running totals, ranking and ties, top-N-per-group, LAG and LEAD, frames, moving averages, and NTILE.

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.

View Comments (2)

Leave a Reply

Subscribe to My Newsletter

Subscribe to my email newsletter to get the latest posts delivered right to your email. Pure inspiration, zero spam.

Discover more from Discuss Data Science, Machine Learning and Analytics

Subscribe now to keep reading and get access to the full archive.

Continue reading