Sql Window Functions — Free Sql Tutorial
Learn Sql Window Functions in Sql with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
TL;DR: Learn Sql Window Functions in Sql with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated
Sql Window Functions in Sql
Window functions perform calculations across a set of rows related to the current row, without collapsing rows like GROUP BY does. They use the OVER() clause.
ROW_NUMBER() assigns sequential numbers. RANK() gives the same rank to ties (with gaps). DENSE_RANK() no gaps. NTILE(n) divides rows into n buckets.
PARTITION BY divides the data into groups (like GROUP BY but rows are preserved). ORDER BY inside OVER() defines the ordering within each partition.
LAG() and LEAD() access the previous/next row's value — perfect for calculating month-over-month changes, running differences, and trends.
Sql Window Functions — Syntax
ROW_NUMBER() OVER (ORDER BY col DESC) RANK() OVER (PARTITION BY dept ORDER BY salary DESC) SUM(amount) OVER (ORDER BY date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) LAG(col) OVER (PARTITION BY category ORDER BY date) PERCENT_RANK() OVER (ORDER BY marks)
Learn Sql Window Functions step by step with Syllab's free interactive Sql tutorial — runnable code examples, practice exercises and instant AI feedback, all free with no signup. Explore the full Sql course →