Interview Questions/SQL/Product Sales Analysis III

Product Sales Analysis III

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Product Sales Analysis III

You have two tables: Sales and Product. Each row in Sales records a sale of a product in a given year. Write a SQL query to select the product_id, the year of its first sale (first_year), the quantity sold, and the price for each product's first year of sale. Return the result in any order.

Examples

Example 1

Product 100 (Nokia) first appeared in 2008 with quantity=10, price=5000. Product 200 (Apple) first appeared in 2011 with quantity=15, price=9000. Product 300 has no sales.

Approach hint

Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

query.sql