LeetCode solutions

1155. Product Sales Analysis III

My accepted SQL solution to LeetCode problem 1155, Product Sales Analysis III, running in 628ms.

  • Difficulty: Medium
  • SQL
  • Runtime 628ms
  • Memory 0.0B

Read the problem on LeetCode View on GitHub

SQL

Accepted on LeetCode — runtime 628ms, memory 0.0B, accepted 2025-12-29.

sql
SELECT s.product_id, s.year AS first_year, s.quantity, s.price
FROM Sales s
JOIN (
    SELECT product_id, MIN(year) AS min_year
        FROM Sales
            GROUP BY product_id
            ) f ON s.product_id = f.product_id AND s.year = f.min_year

Source