Coding question · DedupMediumAsked at Stripe

Each customer's most recent order

Dedup via ROW_NUMBER + PARTITION.

Back to all coding questions

The Brief

Retail AnalyticsCRM team#coding-interview

For each customer, return their most recent order. Columns: `customer_id`, `product_name`, `order_date` (as YYYY-MM-DD text), `revenue`. Order by customer_id. Table: `ci_orders`.

Tables & columns available

ci_ordersfact6 columns
ColumnTypeKey
order_idINTPK
customer_idINT
product_nameTEXT
categoryTEXT
order_dateDATE
revenueNUMERIC

Hints (3)

Each hint you reveal reduces the XP you can earn. Try the query first.

Hint 1

ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY order_date DESC).

Hint 2

Filter where the row number = 1 in an outer query or CTE.

Hint 3

Cast the date with TO_CHAR(order_date, 'YYYY-MM-DD') so the column is a plain text date.