AnalystPath

Debut Harvest of Each Wine

SQLMediumMid level~15 min

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
vintage_idwine_idharvest_yearbottlesprice
110020081050
210020091250
720020111590

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

Related SQL questions