Lesson 17 of 22 · PostgreSQL

Window Functions

Learn PostgreSQL window functions: ROW_NUMBER, RANK, LAG and running totals with OVER().

Window functions perform calculations across rows without collapsing results.

Common Functions

  • ROW_NUMBER() — unique sequential number
  • RANK() — rank with gaps
  • DENSE_RANK() — rank without gaps
  • LAG() / LEAD() — previous/next values
  • SUM() OVER() — running total

Your challenge

Number the users in the order they joined: return each name with a join_order column, where 1 is the earliest sign-up.

Solve it in your browser

Free, no sign-up. The PostgreSQL database runs in your browser; your answer is checked instantly, with hints if you need them. Plus a 1-question quiz.