Fixed Deposits Maturing in March 2025 — SQL Dates Problem
Relationship managers call customers a month before their fixed deposits mature, to offer a renewal.
- Difficulty: Easy
- Topics: Dates
- Dialect: MySQL
- Problem: #52
Problem statement
Relationship managers call customers a month before their fixed deposits mature, to offer a renewal. A deposit matures exactly tenure_months months after its start_date (the same day of the month).
Return fd_id, customer_name and maturity_date for every deposit that matures in March 2025 (1 to 31 March inclusive). Order the rows by maturity_date, then by fd_id.
Tables
Table: FixedDeposit
| Column | Type |
|---|---|
| fd_id | int |
| customer_name | varchar |
| principal | int |
| rate_pct | decimal |
| start_date | date |
| tenure_months | int |
Primary key: fd_id.
One row per fixed deposit. Start dates always fall on day 1–28 of a month.
Examples
Example 1
FixedDeposit
| fd_id | customer_name | principal | rate_pct | start_date | tenure_months |
|---|---|---|---|---|---|
| 1 | Meera Iyer | 200000 | 7.1 | 2024-03-15 | 12 |
| 2 | Rahul Verma | 50000 | 6.8 | 2024-09-01 | 6 |
| 3 | Ananya Das | 500000 | 7.25 | 2022-03-28 | 36 |
| 4 | Vikram Singh | 100000 | 7 | 2024-04-01 | 12 |
| 5 | Zara Khan | 75000 | 6.5 | 2024-12-10 | 3 |
| 6 | Harsh Patel | 300000 | 7.1 | 2023-02-20 | 24 |
Output
| fd_id | customer_name | maturity_date |
|---|---|---|
| 2 | Rahul Verma | 2025-03-01 |
| 5 | Zara Khan | 2025-03-10 |
| 1 | Meera Iyer | 2025-03-15 |
| 3 | Ananya Das | 2025-03-28 |
How to solve Fixed Deposits Maturing in March 2025
The maturity date is derived, not stored: DATE_ADD(start_date, INTERVAL tenure_months MONTH) moves each start date forward by its own tenure, keeping the day of the month (the start dates stop at the 28th, so no month-end clamping is involved). Select it under the name maturity_date and filter on the same expression.
The filter can be a range (BETWEEN '2025-03-01' AND '2025-03-31', inclusive at both ends), a YEAR(...) = 2025 AND MONTH(...) = 3 pair, or DATE_FORMAT(..., '%Y-%m') = '2025-03'. All three are equivalent here. In a real table the range form is preferred when the date is a stored, indexed column — but because this one is computed, every form scans the table.
A column alias cannot be used in the WHERE of the same query (it is evaluated before SELECT), so either repeat the expression or compute it in a derived table and filter outside, as one alternative does. The order is fixed by maturity date with fd_id breaking ties.
Reference solution (MySQL)
SELECT fd_id, customer_name, DATE_ADD(start_date, INTERVAL tenure_months MONTH) AS maturity_date
FROM FixedDeposit
WHERE DATE_ADD(start_date, INTERVAL tenure_months MONTH) BETWEEN '2025-03-01' AND '2025-03-31'
ORDER BY maturity_date, fd_idAnother way
SELECT fd_id, customer_name, maturity_date FROM (
SELECT fd_id, customer_name, DATE_ADD(start_date, INTERVAL tenure_months MONTH) AS maturity_date FROM FixedDeposit
) t WHERE YEAR(maturity_date) = 2025 AND MONTH(maturity_date) = 3 ORDER BY maturity_date, fd_idAnother way
SELECT fd_id, customer_name, DATE_ADD(start_date, INTERVAL tenure_months MONTH) AS maturity_date FROM FixedDeposit WHERE DATE_FORMAT(DATE_ADD(start_date, INTERVAL tenure_months MONTH), '%Y-%m') = '2025-03' ORDER BY maturity_date, fd_id← Masked Card Numbers for Card Statements · Loan Applicants by Credit Score Band →