Skip to main content
Back to problems
Leetcode
Easy
Arrays
Hash Maps
Product Sales Analysis I

Find the products and years for which each product was sold, along with the corresponding price.

Acceptance 100%
Problem Statement

Product Sales Analysis I

You are given sales records for products. Each record tells you which product was sold, in what year, and at what price.

Return a table containing the product name, the sale year, and the price for every sale record.

The result should include one row per sale record.

Input Format

The input is described by two tables:

  • Sales(product_id, year, quantity, price)
  • Product(product_id, product_name)

Each row in Sales represents a product sold in a given year at a given price.

Output Format

Return the columns:

  • product_name
  • year
  • price

One row should be returned for each row in Sales.

Constraints

  • Each sale record belongs to exactly one product.
  • product_id can be used to match sales to product names.
  • Keep all sale records in the output.
  • Output ordering is not important unless required by the platform.
Examples
Sample cases returned by the problem API.

Example 1

Input

Sales
+------------+------+----------+-------+
| product_id | year | quantity | price |
+------------+------+----------+-------+
| 100        | 2008 | 10       | 5000  |
| 100        | 2009 | 12       | 5000  |
| 200        | 2011 | 15       | 9000  |
+------------+------+----------+-------+
Product
+------------+--------------+
| product_id | product_name |
+------------+--------------+
| 100        | Nokia        |
| 200        | Apple        |
+------------+--------------+

Output

+--------------+------+-------+
| product_name | year | price |
+--------------+------+-------+
| Nokia        | 2008 | 5000  |
| Nokia        | 2009 | 5000  |
| Apple        | 2011 | 9000  |
+--------------+------+-------+

Explanation

Match each sale record to its product name using product_id, then project the requested columns.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.