SQL Challenge: Finding Each Customer's Second Purchase with ROW_NUMBER()

A SQL challenge published on DEV Community asks readers to identify the second purchase made by each customer from an orders table. The task requires using the ROW_NUMBER() window function with PARTITION BY customer_id and ordering by order date, so that only the second order per customer is returned. The article explains that the original table is left unchanged because the solution is a read-only SELECT query. It also notes that a customer with only one order, such as C103, has no second purchase to show, and it suggests readers try the third-purchase variant as an exercise.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in