For every Sales record, report product_name, year and the per-unit price, using the Product lookup. Preserve separate sales rows even when their projected output cells coincide. Result row order is unrestricted.
### Problem
For every Sales record, report product_name, year and the per-unit price, using the Product lookup. Preserve separate sales rows even when their projected output cells coincide. Result row order is unrestricted.
### Tables
Table: `Sales`
```text
+-------------+-------+
| 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`
```text
+--------------+---------+
| 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.
```
### Example
```text
Product (product_id,product_name): (10,Widget), (20,Gadget)
Sales (sale_id,product_id,year,quantity,price): (1,10,2021,3,25), (2,10,2021,4,25), (3,20,2022,2,40)
Output (product_name,year,price): (Widget,2021,25), (Widget,2021,25), (Gadget,2022,40)
```
### What a Strong Answer Covers
- Return the requested product information for every sale.
- Keep each sale as its own row when projected values are identical, and report per-unit price.
### Follow-up Questions
- How would the output change if a sale could refer to an unknown product?
- How would you report total sales revenue per product and year?
Overview: For every Sales record, report product_name, year and the per-unit price, using the Product lookup. Preserve separate sales rows even when their projected output cells coincide. Result row order is unrestricted.
For every Sales record, report product_name, year and the per-unit price, using the Product lookup. Preserve separate sales rows even when their projected output cells coincide. Result row order is unrestricted.
Tables
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.