Skip to content

task: #1084 #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
54 changes: 54 additions & 0 deletions leetcode/easy/1084. Sales Analysis III.sql
Original file line number Diff line number Diff line change
@@ -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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy