Skip to content
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 @@ -46,6 +46,7 @@ Have a good contributing!
- [610. Triangle Judgement](./leetcode/easy/610.%20Triangle%20Judgement.sql)
- [619. Biggest Single Number](./leetcode/easy/619.%20Biggest%20Single%20Number.sql)
- [620. Not Boring Movies](./leetcode/easy/620.%20Not%20Boring%20Movies.sql)
- [1068. Product Sales Analysis I](./leetcode/easy/1068.%20Product%20Sales%20Analysis%20I.sql)
2. [Medium](./leetcode/medium/)
- [176. Second Highest Salary](./leetcode/medium/176.%20Second%20Highest%20Salary.sql)
- [184. Department Highest Salary](./leetcode/medium/184.%20Department%20Highest%20Salary.sql)
Expand Down
46 changes: 46 additions & 0 deletions leetcode/easy/1068. Product Sales Analysis I.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Question 1068. Product Sales Analysis I
Link: https://leetcode.com/problems/product-sales-analysis-i/description/

Table: Sales

+-------------+-------+
| Column Name | Type |
+-------------+-------+
| sale_id | int |
| product_id | int |
| year | int |
| quantity | int |
| price | int |
+-------------+-------+
(sale_id, year) is the primary key (combination of columns with unique values) of this table.
product_id is a foreign key (reference column) to Product table.
Each row of this table shows a sale on the product product_id in a certain year.
Note that the price is per unit.


Table: Product

+--------------+---------+
| Column Name | Type |
+--------------+---------+
| product_id | int |
| product_name | varchar |
+--------------+---------+
product_id is the primary key (column with unique values) of this table.
Each row of this table indicates the product name of each product.


Write a solution to report the product_name, year, and price for each sale_id in the Sales table.

Return the resulting table in any order.
*/

SELECT
p.product_name,
s.year,
s.price
FROM Sales AS s
LEFT JOIN
Product AS p
ON s.product_id = p.product_id