9 programs
Choose the best training program according to your career.
Improve the performance of your business with our innovative Industrial Training Program.
Read More →
Our instructor-led training classes are designed to make you an expert.
Read More →
Real-life case studies are a great way to demonstrate your practical knowledge.
Read More →
Explore blogs, latest technologies and industry updates with practical examples.
Read More →Browse all available training programs and choose the right one for your career.
Read More →Know more about who we are and what we stand for.
Discover our mission to equip individuals with essential IT skills and industry expertise.
Read More →Learn, practice and plan your career — bilkul free.
Book a free video counselling session and pick the right course for you.
Read More →This page lists Uncodemy's SQL Window Functions PDFs, each as its own file. A window function calculates across a set of related rows while keeping every row in the result. The key syntax is a function followed by OVER with optional PARTITION BY and ORDER BY.
A normal aggregate with GROUP BY collapses rows. A window function does not: each row stays, and the function looks at a defined window of related rows. This makes ranking, running totals, comparisons with the previous row and share-of-total calculations possible in one query.
Window functions in SQL fall into three primary functional families:
| Family | Functions | Used for |
|---|---|---|
| Ranking | ROW_NUMBER, RANK, DENSE_RANK, NTILE |
Top N per group, percentiles |
| Offset | LAG, LEAD, FIRST_VALUE |
Change from previous row, first in group |
| Aggregate | SUM, AVG, COUNT with OVER |
Running totals, moving averages, share of total |
Tied salaries show how the three ranking functions differ in SQL execution:
SELECT name, salary,
ROW_NUMBER() OVER (ORDER BY salary DESC) AS rn,
RANK() OVER (ORDER BY salary DESC) AS rk,
DENSE_RANK() OVER (ORDER BY salary DESC) AS drk
FROM employees;
-- ROW_NUMBER never repeats; RANK repeats and skips (1,2,2,4);
-- DENSE_RANK repeats without gaps (1,2,2,3).
Three common analyst patterns combined in a single clean query:
SELECT order_id, order_date, amount,
SUM(amount) OVER (ORDER BY order_date, order_id) AS running_total,
LAG(amount) OVER (ORDER BY order_date, order_id) AS previous_amount,
ROUND(amount * 100.0 / SUM(amount) OVER (), 1) AS pct_of_total
FROM orders;
A three-row moving sum uses a frame clause to bound the calculation window:
SELECT order_date, amount,
SUM(amount) OVER (
ORDER BY order_date
ROWS BETWEEN 2 PRECEDING AND CURRENT ROW
) AS moving_sum_3
FROM orders;
Master advanced SQL, data analytics, and real business problem solving with live hands-on projects and 1-on-1 industry mentor guidance at Uncodemy.
Explore Data Analytics Course