Find Overdue Rentals That Have Not Been Returned

Quick Overview

Write a SQL query that lists rentals that are still not returned and whose due date falls before a fixed reference date, sorted by due date and rental id. It tests NULL handling with IS NULL, strict date comparisons and deterministic ordering.

Find Overdue Rentals That Have Not Been Returned

Company: Microsoft

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

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`. ```hint NULL checks Think about what a comparison such as `ReturnDate = NULL` evaluates to in SQL. ``` ### 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.

Overview: Write a SQL query that lists rentals that are still not returned and whose due date falls before a fixed reference date, sorted by due date and rental id. It tests NULL handling with IS NULL, strict date comparisons and deterministic ordering.

Microsoft logo
Microsoft
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

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

ColumnTypeMeaning
RentalIDINTRental identifier. Primary key.
CustomerIDINTCustomer who made the rental. Not null.
RentalDateDATEDate the rental started. Not null.
DueDateDATEDate the item was due back. Not null.
ReturnDateDATEDate 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

RentalIDCustomerIDRentalDateDueDateReturnDate
11012024-04-012024-04-15NULL
21022024-05-012024-05-202024-05-18
31032024-05-102024-05-25NULL
41042024-05-152024-06-10NULL
51052024-03-012024-03-15NULL

Expected output:

RentalIDCustomerIDDueDate
51052024-03-15
11012024-04-15
31032024-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.