leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 9800ac7404cc842f89597fbc99b2a9da1f70b529
parent 3a166d7622512b15902d0dc8289c5921f35f0a50
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Thu, 13 Apr 2023 15:07:17 -0500

Completed SQL problem using aggregation and having along with sum

Diffstat:
Alist-the-products-ordered-in-period/list-the-products.sql | 15+++++++++++++++
1 file changed, 15 insertions(+), 0 deletions(-)

diff --git a/list-the-products-ordered-in-period/list-the-products.sql b/list-the-products-ordered-in-period/list-the-products.sql @@ -0,0 +1,15 @@ +--Runtime: 1363ms Beats: 33.21% + +--The sum gets the added total of the unit values given that this is an aggregated list it is the sum +--of all the units sold of a given product id. +SELECT P.product_name, sum(O.unit ) AS unit +FROM Products AS P + JOIN Orders as O +ON O.product_id = P.product_id +--Only when the date is in February of 2020 +WHERE O.order_date >= '2020-02-01' AND O.order_date < '2020-03-01' +--This aggregates the rows to allow for the sum to only return the sum of the +--values with a given product id. +GROUP BY P.product_id +--Having is used to check the total of the aggregated values +HAVING unit >= 100