list-the-products.sql (619B)
1 --Runtime: 1363ms Beats: 33.21% 2 3 --The sum gets the added total of the unit values given that this is an aggregated list it is the sum 4 --of all the units sold of a given product id. 5 SELECT P.product_name, sum(O.unit ) AS unit 6 FROM Products AS P 7 JOIN Orders as O 8 ON O.product_id = P.product_id 9 --Only when the date is in February of 2020 10 WHERE O.order_date >= '2020-02-01' AND O.order_date < '2020-03-01' 11 --This aggregates the rows to allow for the sum to only return the sum of the 12 --values with a given product id. 13 GROUP BY P.product_id 14 --Having is used to check the total of the aggregated values 15 HAVING unit >= 100