Running Order Total Per User

Medium
Window Functions
Aggregations
Salesforce
Snowflake

Running Order Total Per User

Given orders(order_id, user_id, amount), compute a cumulative sum of amount per user_id ordered by order_id. Return user_id, order_id, amount, running_total sorted by user_id asc, order_id asc. Round to 2 decimals.

Sample input

order_iduser_idamount
1364.57
2325.61
3396.67
4137.55
5265.22
6182.34
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.orders8 rows
order_id (int)user_id (int)amount (double)
1364.57
2325.61
3396.67
4137.55
5265.22
6182.34
7346.04
8387.64

Return these columns

user_id(int)
order_id(int)
amount(double)
running_total(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.