SQL
Top N rows per group
Get the latest or highest N rows for each category using ROW_NUMBER in a subquery.
Loading snippets…
4 snippets
Get the latest or highest N rows for each category using ROW_NUMBER in a subquery.
Understand how the three ranking window functions treat ties, with one query that shows all three.
Show each row's share of the grand total or of its group without a self-join.
Compute a 7-day rolling average with AVG over a ROWS BETWEEN frame.