 Beats 99% - List the Products Ordered in a Period
IntuitionThe problem requires us to find product names where the total units ordered in February 2020 are at least 100. To do this, we need to filter orders wit
# Intuition
The problem requires us to find product names where the total units ordered in February 2020 are at least 100. To do this, we need to filter orders within the given date range and sum up the units per product.

# Approach
1. **Join `Products` and `Orders` tables** using `PRODUCT_ID` to associate product names with their orders.
2. **Filter orders within February 2020** using the `WHERE` clause (`ORDER_DATE BETWEEN '2020-02-01' AND '2020-02-29'`).
3. **Group by `PRODUCT_NAME`** to ensure we sum up the units per product correctly.
4. **Use `HAVING SUM(O.UNIT) >= 100`** to return only products with total units ordered >= 100.

# Complexity
- Time complexity:  
  - The query involves an `INNER JOIN`, filtering, grouping, and aggregation, making the complexity **O(N log N)** in the worst case (due to sorting in `GROUP BY`).
- Space complexity:  
  - **O(1)** since we are not using extra space apart from the result set.

# Code
```mysql
# Write your MySQL query statement below
SELECT P.PRODUCT_NAME, SUM(O.UNIT) AS UNIT  
FROM PRODUCTS P  
INNER JOIN ORDERS O  
ON P.PRODUCT_ID = O.PRODUCT_ID  
WHERE O.ORDER_DATE BETWEEN '2020-02-01' AND '2020-02-29'  
GROUP BY P.PRODUCT_NAME  
HAVING SUM(O.UNIT) >= 100;

['Database', 'MySQL']