AnalystPath

Coffee Cupping Leaderboard

SQLMediumMid level~15 min

Problem

At a coffee cupping event, each sample receives a quality grade in `points` with two decimals.

Table: `cupping_results`

| Column | Type |
|------------|--------------|
| sample_id | int |
| points | decimal(4,2) |

`sample_id` is the primary key.

Write a query that assigns each sample a competition placing in a column named `placing`, following these rules:
- More `points` place better (placing 1 is the best).
- Samples with equal `points` share the same placing.
- Placings are consecutive with no gaps: after a tie, the next placing is the next whole number.

Return `points` and `placing`, ordered by `points` descending.

Tables

Example rows — the live problem includes the full dataset.

cupping_results
sample_idpoints
187.5
288.25
391

Expected output

Your answer should return 6 rows with the columns points, placing.

Starter code (SQL)

SELECT *
FROM cupping_results;

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