First Order Per Customer

Easy
Window Functions
Ranking

First Order Per Customer

Each row in orders is a purchase. For every customer, keep only their earliest order. If two orders share the earliest day, keep the smaller order_id.

Return customer_id, order_id, order_day, amount, sorted by customer_id ascending.

Browser Engine: Evaluates PySpark DataFrame & SQL logic locally in Pyodide WebAssembly.

Input data

1 DataFrame

These DataFrames are passed to solve(spark, dfs). Access one with dfs['name'].

df.orders7 rows
order_id (int)customer_id (int)order_day (int)amount (double)
1001330
1011120
1022250
1032215
1043570
1054410
1064125

Return these columns

customer_id(int)
order_id(int)
order_day(int)
amount(double)

Column names and order must match. Sort order is specified in the question.

Browser engine
Loading Python editor…
Click Run to try the sample cases, or Submit to check the hidden cases. First run caches the browser Python engine (~8–15s once); all code stays on your device.