0
0
SQLquery~5 mins

OVER clause with PARTITION BY in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the OVER clause with PARTITION BY do in SQL?
It divides the result set into partitions (groups) and performs a window function on each partition separately, without collapsing rows.
Click to reveal answer
beginner
How is PARTITION BY different from GROUP BY?
PARTITION BY groups rows for window functions but keeps all rows in the output, while GROUP BY aggregates rows and reduces the number of rows returned.
Click to reveal answer
intermediate
Example: What does this query do?
SELECT department, employee, salary, RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS rank FROM employees;
It ranks employees by salary within each department, showing the highest salary as rank 1 for each department separately.
Click to reveal answer
intermediate
Can you use ORDER BY inside the OVER clause with PARTITION BY? Why?
Yes, ORDER BY inside OVER defines the order of rows within each partition for the window function to calculate results like rank or running totals.
Click to reveal answer
beginner
True or False: The OVER clause with PARTITION BY changes the number of rows returned by the query.
False. It keeps all rows but adds calculated columns based on partitions.
Click to reveal answer
What does PARTITION BY do in an OVER clause?
AGroups rows for window function calculations without reducing rows
BAggregates rows and reduces the number of rows
CSorts the entire result set
DFilters rows based on a condition
Which window function can be used with OVER (PARTITION BY ... ORDER BY ...)?
ACOUNT() without OVER
BDELETE
CSUM() without OVER
DRANK()
Does using PARTITION BY inside OVER clause reduce the number of rows returned?
AYes, it filters rows
BYes, it aggregates rows
CNo, it keeps all rows
DNo, it deletes rows
What is the purpose of ORDER BY inside the OVER clause with PARTITION BY?
ATo order rows within each partition for window function calculation
BTo order the entire result set
CTo filter rows
DTo group rows
Which SQL clause would you use to calculate a running total per group?
AGROUP BY
BOVER (PARTITION BY ... ORDER BY ...)
CWHERE
DHAVING
Explain how the OVER clause with PARTITION BY works and give a simple example.
Think about dividing rows into groups but keeping all rows visible.
You got /3 concepts.
    Describe a real-life scenario where you would use the OVER clause with PARTITION BY in a query.
    Imagine you want to rank or sum values within categories without losing detail.
    You got /3 concepts.