Debut Harvest of Each Wine
Problem
Table: `vintage`
| Column Name | Type |
|---|---|
| vintage_id | int |
| wine_id | int |
| harvest_year | int |
| bottles | int |
| price | int |
`(vintage_id, harvest_year)` is the primary key. Each row records one bottling of a wine in a given year; a wine may have several rows in the same year.
For each `wine_id`, find the earliest `harvest_year` it appears in the table and return every row from that debut year. Output the columns `wine_id`, `first_year`, `bottles`, and `price`. Return the result in any order.
Tables
Example rows — the live problem includes the full dataset.
| vintage_id | wine_id | harvest_year | bottles | price |
|---|---|---|---|---|
| 1 | 100 | 2008 | 10 | 50 |
| 2 | 100 | 2009 | 12 | 50 |
| 7 | 200 | 2011 | 15 | 90 |
Expected output
Your answer should return 2 rows with the columns wine_id, first_year, bottles, price.
Starter code (SQL)
SELECT *
FROM vintage;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock