Recall & Review
beginner
What is a window function in SQL?
A window function performs a calculation across a set of table rows related to the current row without collapsing the result into a single output row. It allows you to keep the original rows while adding aggregated or ranked data.
Click to reveal answer
intermediate
Why are advanced window functions important in data analysis?
They let you perform complex calculations like running totals, moving averages, and ranking within groups efficiently, all while preserving the original data rows for detailed insights.Click to reveal answer
intermediate
Name three common advanced window functions.
ROW_NUMBER(), RANK(), and LAG() are common advanced window functions used for ranking rows, handling ties, and accessing previous row values respectively.
Click to reveal answer
intermediate
How do window functions differ from GROUP BY aggregations?
GROUP BY aggregates rows into fewer rows, losing detail, while window functions calculate over a set of rows but keep each original row intact, adding extra info without losing detail.
Click to reveal answer
beginner
Give a real-life example where advanced window functions help.
In sales data, you can use window functions to calculate a running total of sales per salesperson over time, helping track progress without losing individual sale details.
Click to reveal answer
What does the ROW_NUMBER() window function do?
✗ Incorrect
ROW_NUMBER() assigns a unique sequential number to each row within a partition, useful for ranking.
Which window function lets you access data from a previous row?
✗ Incorrect
LAG() allows you to look at the value from a previous row in the window.
What is a key advantage of window functions over GROUP BY?
✗ Incorrect
Window functions keep all original rows and add extra calculated columns without grouping rows.
Which function would you use to rank rows with ties getting the same rank?
✗ Incorrect
RANK() assigns the same rank to tied rows but skips ranks after ties.
Why might you use a running total with window functions?
✗ Incorrect
Running totals show cumulative sums over rows, useful for trends, while keeping all rows.
Explain in your own words why advanced window functions are useful compared to simple aggregation.
Think about how you can add extra info without losing details.
You got /3 concepts.
Describe a scenario where you would use the LAG() function and what problem it solves.
Imagine you want to see how a value changed from one row to the next.
You got /3 concepts.