Leetcode SQL 50 -- 1068. Product Sales Analysis I
Question
Table name: Sales
Column Name | Type |
---|---|
sale_id | int |
product_id | int |
year | int |
quantity | int |
price | int |
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 name: Product
Column Name | Type |
---|---|
product_id | int |
product_name | varchar |
Each row of this table indicates the product name
of each product.
Write a solution to report the
product_name
,year
, andprice
for eachsale_id
in theSales
table.
Explaination
This question is a basic usage of JOIN
query.
Just be careful on which table you are referring when you select the columns.
Solution
SELECT Product.product_name, Sales.year, Sales.price
FROM Sales
INNER JOIN Product ON Sales.product_id = Product.product_id;
More SQL 50 questions: here
Leetcode SQL 50 -- 1068. Product Sales Analysis I