Find every overdue rental in the Rentals table. A rental is overdue when it has not been returned (ReturnDate is NULL) and its DueDate is before the reference date 2024-06-01.
Input Table(s)
Rentals
| Column | Type | Meaning |
|---|
| RentalID | INT | Rental identifier. Primary key. |
| CustomerID | INT | Customer who made the rental. Not null. |
| RentalDate | DATE | Date the rental started. Not null. |
| DueDate | DATE | Date the item was due back. Not null. |
| ReturnDate | DATE | Date the item was returned, or NULL if it is still out. |
Key: RentalID is the primary key.
Output Contract
-
Columns, in this order:
RentalID
,
CustomerID
,
DueDate
.
-
One row per overdue rental.
-
Order by
DueDate
ascending, then
RentalID
ascending.
RentalID
is unique, so the order is fully determined.
-
Return an empty result when no rental is overdue.
Example
Rentals
| RentalID | CustomerID | RentalDate | DueDate | ReturnDate |
|---|
| 1 | 101 | 2024-04-01 | 2024-04-15 | NULL |
| 2 | 102 | 2024-05-01 | 2024-05-20 | 2024-05-18 |
| 3 | 103 | 2024-05-10 | 2024-05-25 | NULL |
| 4 | 104 | 2024-05-15 | 2024-06-10 | NULL |
| 5 | 105 | 2024-03-01 | 2024-03-15 | NULL |
Expected output:
| RentalID | CustomerID | DueDate |
|---|
| 5 | 105 | 2024-03-15 |
| 1 | 101 | 2024-04-15 |
| 3 | 103 | 2024-05-25 |
Rental 2 was returned, so it is not overdue. Rental 4 is still out, but its due date of 2024-06-10 falls after the reference date. The remaining three rentals are listed from the earliest due date.
Constraints and Clarifications
-
Rentals
has at most 10,000 rows.
-
Use the fixed reference date
2024-06-01
, not the current date.
-
The comparison is strict: a rental due on 2024-06-01 itself is not overdue.
-
A rental with a non-
NULL
ReturnDate
is excluded, even if it came back after its due date. Only rentals that are still out count.