ROW_NUMBER
Assigns a unique, gapless sequence number to each row โ the easiest window function to learn first.
Your first step into window functions โ ROW_NUMBER, RANK, DENSE_RANK, PARTITION BY, LAG and LEAD, taught through real e-commerce scenarios.
categories, users, products, orders, order_items, payments.You need to be logged in to take this challenge.
A window function looks at a group of related rows โ a "window" โ and calculates something for each row without merging those rows into one, the way GROUP BY does. If you already know SELECT, WHERE, GROUP BY, ORDER BY, and simple aggregates like SUM() and COUNT(), you already have everything you need to start.
This challenge uses the same friendly e-commerce dataset you'll see across SQLab Hub โ customers, orders, order items, products, categories, and payments โ so what you learn here carries straight into the Medium and Hard Window Functions challenges.
Almost every real analytics question โ "who are our top customers," "what's the order history for this customer," "how is revenue trending" โ is naturally answered with a window function. Learning them early means you stop reaching for complicated self-joins or spreadsheet-style manual math.
All three number rows in order, but they handle ties differently. ROW_NUMBER() always gives a unique number, even to ties. RANK() gives tied rows the same number, then skips ahead (1, 2, 2, 4). DENSE_RANK() also ties them together, but never skips a number (1, 2, 2, 3). Challenge 10 below lets you see ROW_NUMBER() and RANK() side by side on the same data so the difference clicks immediately.
PARTITION BY resets a window function at the start of every group. Without it, ROW_NUMBER() counts through your entire result set; with PARTITION BY customer_id, it restarts at 1 for every customer. It's the single most important idea to master before moving on to Medium-level challenges.
LAG() reaches back to a previous row, and LEAD() reaches forward to the next one โ both within whatever PARTITION BY and ORDER BY you set. They're the simplest way to compare "this row" to "the row right before or after it," which is exactly what a "previous order amount" or "next order date" question needs.
Data analyst and BI interviews almost always include a ranking or ordering question. This challenge builds the fundamentals โ ROW_NUMBER, RANK, DENSE_RANK, PARTITION BY, LAG, LEAD, and a simple running total โ with 10 beginner-friendly, scenario-driven questions, each evaluated against real query output.
Passing at 60/100 unlocks a shareable certificate, and every attempt is eligible for the Window Functions Easy Challenge leaderboard. Once you're comfortable here, move on to the Window Functions Medium Challenge and eventually the Window Functions Hard Challenge.
Assigns a unique, gapless sequence number to each row โ the easiest window function to learn first.
Ranks rows within an order, leaving a gap after ties (1, 2, 2, 4).
Ranks rows within an order without ever leaving a gap after ties (1, 2, 2, 3).
Splits a result set into independent groups so a window function restarts fresh for each group โ like "per customer" or "per category".
Looks back to the previous row โ beginner-friendly for 'what was the value before this one?'.
Looks ahead to the next row โ the mirror image of LAG().