ROW_NUMBER()
Assigns a unique, gapless sequence number to each row within a partition โ the foundation of "top-N per group" queries.
A real technical SQL interview, built around ROW_NUMBER, RANK, DENSE_RANK, NTILE, LAG, LEAD, FIRST_VALUE and LAST_VALUE.
categories, users, products, orders, order_items, payments.You need to be logged in to take this challenge.
Window functions compute a value across a set of rows related to the current row โ a "window" โ without collapsing those rows into a single output row the way GROUP BY does. That distinction is exactly why interviewers reach for window-function questions: they reveal whether a candidate can reason about ranking, running totals, and row-to-row comparisons in the same query, rather than falling back to self-joins or client-side post-processing.
This challenge is built around a realistic e-commerce dataset โ customers, orders, order items, products, categories, and payments โ because that is the shape of data window-function questions are asked against at Google, Amazon, Uber, Airbnb, Microsoft, Meta, Netflix, Flipkart, Razorpay, Swiggy, and Zomato.
Nearly every analytics, BI, and data-engineering role eventually needs a "top customer per category," a "month-over-month growth," or a "running total" query โ and window functions are the idiomatic, performant way to write them. Interviewers use these questions to separate candidates who memorized SELECT/JOIN/GROUP BY from candidates who can reason about partitions, frames, and ordering the way a production analytics pipeline requires.
Assigns a unique, gapless sequence number to each row within a partition โ the foundation of "top-N per group" queries.
Ranks rows within a partition, leaving gaps after ties (1, 2, 2, 4).
Ranks rows within a partition without gaps after ties (1, 2, 2, 3).
Splits ordered rows into N roughly equal buckets โ used for percentile/quartile segmentation.
Looks back to a previous row in the same partition โ the backbone of period-over-period comparisons.
Looks ahead to a following row in the same partition โ used for "what happens next" analysis.
Returns the first value in an ordered window frame, e.g. a customer's largest order.
Returns the last value in an ordered window frame โ needs an explicit frame to behave intuitively.
Data analyst, BI analyst, analytics engineer, and product analyst interviews consistently include at least one window-function question โ most often ranking within a group (ROW_NUMBER/RANK/DENSE_RANK) or a period-over-period comparison (LAG/LEAD). This challenge mirrors that format exactly: 20 scenario-driven questions, each requiring a specific window function, evaluated against real query output โ not multiple choice.
Passing at 75/100 unlocks a shareable certificate with your score and completion date, and every attempt is eligible for the Window Functions Hard Challenge leaderboard.
Before attempting this challenge, make sure you can explain PARTITION BY vs. GROUP BY, the difference between RANK() and DENSE_RANK() under ties, and when a frame clause (ROWS BETWEEN ...) changes the result of LAST_VALUE(). If any of those feel shaky, work through the SQL Practice Challenges first, or open the SQL Playground to experiment against the same style of e-commerce schema used here.