Looking for a simpler alternative to raw SQL? Check out the built-in row functions and pivot functions — they handle common patterns like accessing previous rows and working across pivot columns without needing to write window function SQL.
SQL templates
SQL templates
Copy-paste SQL patterns for common table calculations like running totals and rankings
Percent change from previous
Calculate the percent change between a value and the value in the row above it
Percent of previous value
Calculate a value as a percentage of the value in the row above it
Percent of column total
Calculate each value as a percentage of its column total
Percent of group/pivot total
Calculate each value as a percentage of its group or pivot total
Rank in column
Rank every value in a column, from the lowest value up
Running total
Running totals give you the sum of a value + all of the previous values in that column.
Rolling window
Calculate rolling averages and lookbacks over the previous N rows