Recall & Review
beginner
What is the main purpose of window functions in SQL?
Window functions allow you to perform calculations across a set of rows related to the current row without collapsing the result into a single output row.
Click to reveal answer
beginner
How do window functions differ from aggregate functions?
Aggregate functions group rows and return one result per group, while window functions compute values across rows but keep each row separate in the output.
Click to reveal answer
intermediate
Why can't aggregate functions alone solve all data analysis problems?
Because aggregate functions reduce multiple rows into one, losing individual row details, whereas window functions keep row details while adding summary info.
Click to reveal answer
beginner
Give a real-life example where window functions are useful.
Calculating a running total of sales per day while still showing each day's sales separately is a common use of window functions.
Click to reveal answer
beginner
What does the OVER() clause do in a window function?
The OVER() clause defines the window or set of rows the function should consider for each row, such as partitioning or ordering the data.
Click to reveal answer
What is a key benefit of using window functions in SQL?
✗ Incorrect
Window functions perform calculations across related rows but keep each row separate, unlike aggregate functions that group rows.
Which clause is essential to define the rows a window function works on?
✗ Incorrect
The OVER() clause specifies the window or set of rows for the window function to operate on.
What happens if you use an aggregate function without a GROUP BY clause?
✗ Incorrect
Aggregate functions without GROUP BY return a single summary result for all rows.
Which of these is NOT a use case for window functions?
✗ Incorrect
Filtering rows is done with WHERE or HAVING clauses, not window functions.
Why might you prefer window functions over subqueries for some calculations?
✗ Incorrect
Window functions often provide clearer syntax and better performance for calculations across rows.
Explain in your own words why window functions are needed in SQL.
Think about how you want to calculate values without losing row details.
You got /4 concepts.
Describe a real-life scenario where window functions help solve a problem.
Imagine you want to see daily sales and also a total that grows each day.
You got /3 concepts.