Leetcode SQL 50 -- 1068. Product Sales Analysis I

  1. Question
    1. Table name: Sales
    2. Table name: Product
  2. Explaination
  3. Solution

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, and price for each sale_id in the Sales 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


Please cite the source for reprints, feel free to verify the sources cited in the article, and point out any errors or lack of clarity of expression. You can comment in the comments section below or email to GreenMeeple@yahoo.com
This Repo