MySQL Clean Simple Solution | With 2 Approaches
Approach\n Describe your approach to solving the problem. \nTo solve this problem, we can follow these steps:\n\n- Look at the Products table and select the pro
# Approach\n<!-- Describe your approach to solving the problem. -->\nTo solve this problem, we can follow these steps:\n\n- Look at the Products table and select the product_name column, which contains the names of the products.\n- Look at the Orders table and find the sum of units for each product using the product_id column that matches the products.\n- Filter the orders to include only those made in the specified period. We check the year and month of the order_date column.\n- Group the results by the product_id so that we can aggregate the units ordered for each product.\n- Finally, apply a condition to include only those products that have a sum of units greater than or equal to 100.\n\n# Code\n```mysql-I []\n# Write your MySQL query statement below\nSELECT product_name, SUM(unit) AS unit \nFROM Products\nJOIN orders\nON Products.product_id = orders.product_id\nWHERE MONTH(order_date)=2 AND YEAR(order_date)=2020\nGROUP BY Products.product_id\nHAVING unit>=100;\n```\n\n```mysql-II []\n# Write your MySQL query statement below\nSELECT p.product_name, SUM(o.unit) AS unit \nFROM Products p\nJOIN Orders o\nON p.product_id = o.product_id\nWHERE o.order_date BETWEEN \'2020-02-01\' AND \'2020-02-29\'\nGROUP BY p.product_id\nHAVING unit >= 100;\n```
['Database', 'MySQL']