Skip to content

Commit d5ca081

Browse files
committed
task: #1084
1 parent e6ffdd5 commit d5ca081

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ Useful for preparing for technical interviews and improving your SQL skills.
123123
- [1050. Actors and Directors Who Cooperated At Least Three Times](./leetcode/easy/1050.%20Actors%20and%20Directors%20Who%20Cooperated%20At%20Least%20Three%20Times.sql)
124124
- [1068. Product Sales Analysis I](./leetcode/easy/1068.%20Product%20Sales%20Analysis%20I.sql)
125125
- [1075. Project Employees I](./leetcode/easy/1075.%20Project%20Employees%20I.sql)
126+
- [1084. Sales Analysis III](./leetcode/easy/1084.%20Sales%20Analysis%20III.sql)
126127
- [1141. User Activity for the Past 30 Days I](./leetcode/easy/1141.%20User%20Activity%20for%20the%20Past%2030%20Days%20I.sql)
127128
- [1148. Article Views I](./leetcode/easy/1148.%20Article%20Views%20I.sql)
128129
- [1179. Reformat Department Table](./leetcode/easy/1179.%20Reformat%20Department%20Table.sql)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Question 1084. Sales Analysis III
3+
Link: https://leetcode.com/problems/sales-analysis-iii/description/?envType=problem-list-v2&envId=database
4+
5+
Table: Product
6+
7+
+--------------+---------+
8+
| Column Name | Type |
9+
+--------------+---------+
10+
| product_id | int |
11+
| product_name | varchar |
12+
| unit_price | int |
13+
+--------------+---------+
14+
product_id is the primary key (column with unique values) of this table.
15+
Each row of this table indicates the name and the price of each product.
16+
Table: Sales
17+
18+
+-------------+---------+
19+
| Column Name | Type |
20+
+-------------+---------+
21+
| seller_id | int |
22+
| product_id | int |
23+
| buyer_id | int |
24+
| sale_date | date |
25+
| quantity | int |
26+
| price | int |
27+
+-------------+---------+
28+
This table can have duplicate rows.
29+
product_id is a foreign key (reference column) to the Product table.
30+
Each row of this table contains some information about one sale.
31+
32+
33+
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.
34+
35+
Return the result table in any order.
36+
*/
37+
38+
WITH sales_other_q AS (
39+
SELECT DISTINCT product_id
40+
FROM Sales
41+
WHERE sale_date NOT BETWEEN '2019-01-01' AND '2019-03-31'
42+
)
43+
44+
SELECT DISTINCT
45+
s.product_id,
46+
p.product_name
47+
FROM Sales AS s
48+
LEFT JOIN
49+
sales_other_q AS q
50+
ON s.product_id = q.product_id
51+
LEFT JOIN
52+
Product AS p
53+
ON s.product_id = p.product_id
54+
WHERE q.product_id IS NULL

0 commit comments

Comments
 (0)