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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
SQL
Accepted on LeetCode — runtime 628ms, memory 0.0B, accepted 2025-12-29.
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