Window Functions

Talk it through out loud with your AI coach.

The problem

  • hard
  • Pro

You need each customer's three most recent orders, and a running total of revenue by day. Explain what window functions are, how they differ from group by, and how you'd use them for both tasks.

What a strong answer covers

  • How a window calculation differs from collapsing rows into groups.
  • How rows are split up and ordered inside a window.
  • An approach to keeping only the top few rows per customer.
  • How a cumulative total is built up row by row.
  • Where a filter on a window result has to go.

Common mistake: Trying to filter on a window function's result in the same where clause that defines it.

Knowing this is half of it. Saying it clearly out loud is the part the coach helps you practise.

Practise it out loud