Top-Selling Product by Units

Easy
Aggregation
Ranking

Top-Selling Product by Units

The sales table contains individual sales rows.

Return product_id, units_sold for the product with the highest total units. If two products tie, choose the smaller product_id. Return exactly one row.

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.sales6 rows
sale_id (int)product_id (string)units (int)
1P15
2P28
3P14
4P38
5P21
6P42

Return these columns

product_id(string)
units_sold(int)

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.