The "List the Products Ordered in a Period interview question" is a SQL challenge. You are given two tables: Products and Orders. You need to find the names of products that had at least 100 units ordered in February 2020 and return their total units. This "List the Products Ordered in a Period coding problem" is a fundamental test of data aggregation and filtering.
This problem is a staple in Data Analyst and Backend Engineer interviews at companies like Amazon and Microsoft. It tests your proficiency with "Database interview pattern" concepts like JOIN, GROUP BY, SUM(), and date filtering. It evaluates whether you can combine data from multiple tables and filter it based on aggregate results.
The solution uses SQL relational operations.
Products and Orders on the product_id.WHERE clause to restrict the results to orders placed in '2020-02'.GROUP BY on the product name or ID.SUM(unit) to calculate the total units for each group.HAVING clause to keep only those groups where the sum is at least 100.Products: {1: "Laptop", 2: "Mouse"}, Orders: {[1, '2020-02-01', 60], [1, '2020-02-15', 50], [2, '2020-02-10', 80]}
WHERE SUM(unit) >= 100, which is invalid SQL (you must use HAVING).LIKE '2020-02%' or BETWEEN incorrectly).Always remember the order of execution in SQL: FROM -> JOIN -> WHERE -> GROUP BY -> HAVING -> SELECT. Understanding that HAVING filters after the aggregation is the most important takeaway for this problem.