0
0
SQLquery~5 mins

Window function vs GROUP BY mental model in SQL - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What is the main difference between a window function and GROUP BY in SQL?
GROUP BY groups rows and returns one result per group, reducing the number of rows. Window functions perform calculations across rows related to the current row without reducing the number of rows.
Click to reveal answer
beginner
How does a window function maintain the original number of rows?
Window functions calculate values over a set of rows defined by a window but return a value for each original row, keeping all rows intact.
Click to reveal answer
beginner
Give a real-life analogy for GROUP BY in SQL.
GROUP BY is like sorting a pile of mail by city and then counting how many letters go to each city. You get one count per city, not per letter.
Click to reveal answer
beginner
Give a real-life analogy for window functions in SQL.
Window functions are like looking at each letter in the mail pile and noting how many letters are from the same city, but you keep each letter separate.
Click to reveal answer
intermediate
Can you use window functions and GROUP BY together in a query?
Yes, you can use GROUP BY to aggregate data and then apply window functions on the aggregated results to perform further calculations without losing row details.
Click to reveal answer
What happens to the number of rows when you use GROUP BY in SQL?
AThe number of rows decreases
BThe number of rows stays the same
CThe number of rows increases
DRows are duplicated
Which SQL feature allows you to calculate a value across rows but keep all original rows?
AWHERE clause
BGROUP BY
CJOIN
DWindow function
If you want to find the total sales per region and also show each sale with the region total, which should you use?
AOnly GROUP BY
BOnly window functions
CGROUP BY with window functions
DNeither
Which of these is true about window functions?
AThey can access data from other rows without grouping
BThey filter rows
CThey only work with GROUP BY
DThey reduce the number of rows
What does GROUP BY do to the data?
AFilters rows
BSorts rows only
CAggregates rows into groups
DDuplicates rows
Explain in your own words how window functions differ from GROUP BY in SQL.
Think about whether the number of rows changes.
You got /4 concepts.
    Describe a real-life example that helps you remember the difference between window functions and GROUP BY.
    Use simple everyday situations like sorting mail or counting items.
    You got /3 concepts.