SQL Window Functions Practice Problems: 305 Questions with Solutions

305 SQL window functions practice problems with solutions: RANK, LAG, LEAD, running totals and top N per group. Written in MySQL, judged on hidden datasets.

  • Problems: 305
  • By difficulty: 1 easy · 126 medium · 178 hard
  • Dialect: MySQL

Practise SQL window functions in MySQL 8: ROW_NUMBER, RANK and DENSE_RANK, LAG and LEAD, running totals with SUM() OVER, moving averages and PARTITION BY. These are the questions behind "top N per group", "second highest salary", "consecutive days" and "month-over-month growth". Learn the joins and GROUP BY problems first.

Easy SQL window functions problems

Medium SQL window functions problems

Hard SQL window functions problems

Every SQL problem · The SQL skill test