Return the single most recent order (latest order_date). If several orders share the latest date, pick the one with the highest amount; if still tied, the lowest order_id. Orders with a NULL order_date are ignored. Return an empty result when there are no dated orders.
| order_id | customer_id | region | product | qty | amount | order_date |
|---|---|---|---|---|---|---|
| 101 | 1 | North | Laptop | 1 | 55000.0 | 2024-01-05 |
| 102 | 2 | South | Phone | 2 | 30000.0 | 2024-01-18 |
| 103 | 1 | North | Mouse | 3 | 1500.0 | 2024-02-02 |
| 104 | 3 | West | Tablet | 1 | 22000.0 | 2024-02-15 |
| 105 | 4 | South | Laptop | 1 | 55000.0 | 2024-03-01 |
| 106 | 2 | East | Headphones | 2 | 4000.0 | 2024-03-09 |
| order_id | customer_id | amount | order_date |
|---|---|---|---|
| 106 | 2 | 4000 | 2024-03-09 |
| order_id | customer_id | region | product | qty | amount | order_date |
|---|---|---|---|---|---|---|
| 201 | 5 | East | Phone | 1 | 15000.0 | 2024-04-12 |
| 202 | 6 | West | Keyboard | 4 | 6000.0 | 2024-04-20 |
| 203 | 5 | North | Mouse | 2 | 999.5 | 2024-05-03 |
| 204 | 7 | North | Tablet | 1 | 25000.0 | 2024-05-21 |
| order_id | customer_id | amount | order_date |
|---|---|---|---|
| 204 | 7 | 25000 | 2024-05-21 |
Return exactly order_id, customer_id, amount, order_date — at most one row.
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Prefix Every Column Name · Select Columns from a Config Table ›
{{ totalCount }} questions · {{ shHardPct }}% Hard. Real PySpark DataFrame and Spark SQL interview questions. Write PySpark in your browser on TechTown’s Spark engine, run sample tests, then submit against hidden tests.
Guests can solve {{ freeLimit }} problems for free. Log in or sign up (free) to unlock everything, keep your streak and appear on the leaderboard. New to a topic? Learn it first in the Spark course.
{{ p.statement }}
{{ p.constraints }}
No submissions yet. Press Submit to judge your code against all tests.
The model solution and step-by-step explanation unlock when you solve this problem or after 3 unsuccessful submissions ({{ shFailsLabel }}). Struggling? Try the hints on the Question tab first.
{{ p.solution }}
Write real PySpark: from pyspark.sql import functions as F, Window, spark.sql(...). It runs in your browser on a lightweight Spark engine, and the same code runs unchanged on Databricks or any Spark cluster. Use df.show() or print() to debug.
Create your free TechTown account to unlock every problem, track your progress, bookmark questions and keep preparing for interviews.