Practice / window functions

Latest Order Per Customer

hard

An online shop wants each customer's most recent order, labelled with their name.

orders

customers

Each customer's orders are on distinct dates, so "most recent" is unambiguous.

Your task: keep the latest order per customer_id (by order_date), join to customers, and return name, order_id, and order_date.

Assign your answer DataFrame to result. Row order doesn't matter.

ordersinput DataFrame

Schema
columntype
order_idlong
customer_idlong
order_datestring
Sample rows
order_idcustomer_idorder_date
11002026-06-01
21002026-06-09
31012026-06-05
41022026-06-02
51022026-06-07

customersinput DataFrame

Schema
columntype
customer_idlong
namestring
Sample rows
customer_idname
100Priya
101Sam
102Wen
Expected output shape
nameorder_idorder_date· 3 rows
Hint

row_number() partitioned by customer_id, ordered by order_date descending; keep rn == 1 to get each customer's latest order, then join customers for the name.

Lesson refresher

This problem builds on Window Functions (~9 min). Pop it open in a new tab if you want a quick recap.

Loading editor…
Hit Run to execute your code and see the output here.