diff --git a/README.md b/README.md index 709a704..62897bd 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ Useful for preparing for technical interviews and improving your SQL skills. - [1050. Actors and Directors Who Cooperated At Least Three Times](./leetcode/easy/1050.%20Actors%20and%20Directors%20Who%20Cooperated%20At%20Least%20Three%20Times.sql) - [1068. Product Sales Analysis I](./leetcode/easy/1068.%20Product%20Sales%20Analysis%20I.sql) - [1075. Project Employees I](./leetcode/easy/1075.%20Project%20Employees%20I.sql) + - [1084. Sales Analysis III](./leetcode/easy/1084.%20Sales%20Analysis%20III.sql) - [1141. User Activity for the Past 30 Days I](./leetcode/easy/1141.%20User%20Activity%20for%20the%20Past%2030%20Days%20I.sql) - [1148. Article Views I](./leetcode/easy/1148.%20Article%20Views%20I.sql) - [1179. Reformat Department Table](./leetcode/easy/1179.%20Reformat%20Department%20Table.sql) diff --git a/leetcode/easy/1084. Sales Analysis III.sql b/leetcode/easy/1084. Sales Analysis III.sql new file mode 100644 index 0000000..7ed5d49 --- /dev/null +++ b/leetcode/easy/1084. Sales Analysis III.sql @@ -0,0 +1,54 @@ +/* +Question 1084. Sales Analysis III +Link: https://leetcode.com/problems/sales-analysis-iii/description/?envType=problem-list-v2&envId=database + +Table: Product + ++--------------+---------+ +| Column Name | Type | ++--------------+---------+ +| product_id | int | +| product_name | varchar | +| unit_price | int | ++--------------+---------+ +product_id is the primary key (column with unique values) of this table. +Each row of this table indicates the name and the price of each product. +Table: Sales + ++-------------+---------+ +| Column Name | Type | ++-------------+---------+ +| seller_id | int | +| product_id | int | +| buyer_id | int | +| sale_date | date | +| quantity | int | +| price | int | ++-------------+---------+ +This table can have duplicate rows. +product_id is a foreign key (reference column) to the Product table. +Each row of this table contains some information about one sale. + + +Write a solution to report the products that were only sold in the first quarter of 2019. That is, between 2019-01-01 and 2019-03-31 inclusive. + +Return the result table in any order. +*/ + +WITH sales_other_q AS ( + SELECT DISTINCT product_id + FROM Sales + WHERE sale_date NOT BETWEEN '2019-01-01' AND '2019-03-31' +) + +SELECT DISTINCT + s.product_id, + p.product_name +FROM Sales AS s +LEFT JOIN + sales_other_q AS q + ON s.product_id = q.product_id +LEFT JOIN + Product AS p + ON s.product_id = p.product_id +WHERE q.product_id IS NULL
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: