Home › coding › sql › sql window functions

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.

✓ 100% Free ✓ No Login Needed ✓ NCERT / CBSE Aligned ✓ Download as PDF

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 Jul 14, 2026

🤖 Stuck on any question? Ask Syllab's free AI Tutor for a step-by-step explanation — instant, unlimited, no login.

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 →

Explore:

  • Syllabus
  • Practice
  • Mock Tests
  • NCERT Solutions
  • Coding
  • GK Quiz
  • Career Predictor
  • AI Tutor
  • Live Quiz
  • Doubt Solver
  • Microlearning
  • Free Alternatives
  • Kids Zone
  • Study Room
  • Calculators
  • Worksheets

Syllab.in — Free learning for Indian students, Class 1–12