The Product Price at a Given Date SQL problem asks you to find the price of each product on a given date. The most recent price change on or before the date is the current price; if no price change exists before the date, the default price is 10. This SQL problem tests the latest-record-before-a-date pattern. The database interview pattern is demonstrated.
Microsoft, Meta, Amazon, Google, and Bloomberg ask this because it's a "point-in-time snapshot" query — find the most recent record satisfying a date constraint. This is a fundamental analytics pattern in pricing, inventory, and historical data systems.
Latest record per product before date + default handling. Use a correlated subquery or window function: SELECT product_id, new_price AS price FROM Products WHERE (product_id, change_date) IN (SELECT product_id, MAX(change_date) FROM Products WHERE change_date <= '2019-08-16' GROUP BY product_id). UNION with default price for products with no changes: SELECT DISTINCT product_id, 10 AS price FROM Products WHERE product_id NOT IN (SELECT product_id FROM Products WHERE change_date <= '2019-08-16').
Products: prod1 changed to 25 on 2019-08-14, prod2 changed to 50 on 2019-08-20. Query date = 2019-08-16.
Point-in-time pricing queries use the "latest record before date" pattern: MAX(date) WHERE date <= target_date GROUP BY id. Always handle the "no record before date" case with a UNION and default value. Practice similar problems: "stock price at date," "exchange rate at time," "employee salary history." These appear across fintech, e-commerce, and enterprise analytics SQL interviews.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Confirmation Rate | Medium | Solve | |
| Product Sales Analysis III | Medium | Solve | |
| Rank Scores | Medium | Solve | |
| Friend Requests II: Who Has the Most Friends | Medium | Solve | |
| Game Play Analysis IV | Medium | Solve |