Leetcode Problem 1070. Product Sales Analysis III

1070. Product Sales Analysis III

Leetcode Solutions

Filtering from Minimum Value Subquery

  1. Write a subquery that groups the Sales table by product_id and selects the minimum year for each group.
  2. In the main query, select the columns product_id, year (aliased as first_year), quantity, and price from the Sales table.
  3. Use a WHERE clause in the main query to filter the results to only include rows where the combination of product_id and year matches the combination returned by the subquery.
  4. Return the final result, which includes the sales information for the first year each product was sold.
erDiagram
    Sales {
        int sale_id
        int product_id
        int year
        int quantity
        int price
    }
    Product {
        int product_id
        varchar product_name
    }
    Sales }|--|| Product : "foreign key"

Group-Merge-Filter Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...