Second-Highest Order

Medium
Window Functions
Ranking

Second-Highest Order

The orders table contains order amounts.

Return order_id, amount for orders whose amount is the second-highest distinct amount. If multiple orders share that amount, return all of them. Sort by order_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.orders5 rows
order_id (int)amount (double)
150
280
320
480
560

Return these columns

order_id(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.