5. Paid Orders in March
Difficulty: Easy · Topics: Filtering & Selection
orders has order_id, status, order_date ('YYYY-MM-DD') and amount.
Return every order placed in March 2025 (the 1st and the 31st included) whose status is 'PAID' or 'SHIPPED'. Return all columns. Orders with a null status are not included.
Row order does not matter; column names must match. Your code is graded on 3 test cases, including hidden edge cases.
Sample data
orders
| order_id | status | order_date | amount |
|---|---|---|---|
| 1 | PAID | 2025-03-05 | 250 |
| 2 | CANCELLED | 2025-03-07 | 90 |
| 3 | SHIPPED | 2025-03-20 | 400 |
| 4 | PAID | 2025-04-02 | 120 |
| 5 | PAID | 2025-02-28 | 60 |
Expected output
| order_id | status | order_date | amount |
|---|---|---|---|
| 1 | PAID | 2025-03-05 | 250 |
| 3 | SHIPPED | 2025-03-20 | 400 |
Hints
Hint 1
Combine conditions with&, each wrapped in parentheses.Hint 2
F.col("order_date").between("2025-03-01", "2025-03-31") includes both ends; ISO date strings compare correctly.Hint 3
F.col("status").isin("PAID", "SHIPPED") is null for a null status, so those rows drop out.Learn the concepts
- filter / where · 4 min read. Keep the rows that match a condition, and the null and operator traps that silently drop data.
PySpark functions you'll practise
- filter
- isin
- between
Related problems
- Filter High Earners · Easy · Filtering & Selection
- Departments with Large Teams · Easy · Aggregations
- Find Repeat Customers · Easy · Aggregations
- Find Partitions That Need Compaction · Easy · Aggregations
- Parse Application Log Lines · Medium · Strings
Browse
Topics: Window Functions · Joins · Aggregations · Pivot, Unpivot & Rollup · Arrays · Null Handling · Conditional Logic · Dates · Filtering & Selection · Strings
Difficulty: Easy · Medium · Hard · PySpark interview roadmap · Learn · All problems