-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1327. List the Products Ordered in a Period.sql
More file actions
46 lines (37 loc) · 1.27 KB
/
1327. List the Products Ordered in a Period.sql
File metadata and controls
46 lines (37 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
Question 1327. List the Products Ordered in a Period
Link: https://leetcode.com/problems/list-the-products-ordered-in-a-period/description/
Table: Products
+------------------+---------+
| Column Name | Type |
+------------------+---------+
| product_id | int |
| product_name | varchar |
| product_category | varchar |
+------------------+---------+
product_id is the primary key (column with unique values) for this table.
This table contains data about the company's products.
Table: Orders
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| product_id | int |
| order_date | date |
| unit | int |
+---------------+---------+
This table may have duplicate rows.
product_id is a foreign key (reference column) to the Products table.
unit is the number of products ordered in order_date.
Write a solution to get the names of products that have at least 100 units ordered in February 2020 and their amount.
Return the result table in any order.
*/
SELECT
p.product_name,
SUM(o.unit) as unit --noqa: CP01
FROM Orders AS o
LEFT JOIN
Products AS p
ON o.product_id = p.product_id
WHERE o.order_date BETWEEN '2020-02-01' AND '2020-02-29'
GROUP BY p.product_name
HAVING SUM(o.unit) >= 100