Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. What does OVER() do? What is PARTITION BY?

SQL · Window Functions

What does OVER() do? What is PARTITION BY?

Mediumsql-17
overpartition bywindow

Question

What does OVER() do? What is PARTITION BY?

Solution

OVER() defines the window over which the calculation happens.

SUM(salary) OVER ()

calculates across all rows.

SUM(salary) OVER (
    PARTITION BY department
)

calculates separately for each department.

GROUP BY:

Many rows → fewer rows

PARTITION BY:

Many rows → still many rows

It just splits the rows into groups for the window calculation. You still keep every row.

🎯 Put this concept into practice

Solidify this answer with real hands-on interview drills in the browser studio.

Open related drill →
PreviousNext