Product Revenue Rank

Medium
Aggregation
Window Functions
Ranking

Product Revenue Rank

The sales table contains revenue rows by product.

Aggregate revenue per product, then rank products by total revenue using dense_rank with the highest revenue as rank 1. Return product_id, revenue, rn, sorted by rn, then product_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.sales6 rows
sale_id (int)product_id (string)revenue (double)
1P1100
2P280
3P380
4P420
5P580
6P110

Return these columns

product_id(string)
revenue(double)
rn(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.