# THE GREAT PIE-OFF

WEEKLY QUACK CHALLENGE! · challenge 21 · medium · 5 guesses

> Head Judge Muscovy sets down a tower of score cards, a blob of custard on one wing. "The Golden Rolling Pin goes to the pie with the best middle score, Duckbert. Line up a pie's scores and take the middle one, or halfway between the middle two when there is no single middle, so no single judge can sink a pie or crown one. Beatrix Butterbill's four cousins each gave her blueberry buckle a ten. Felix says his fig tart is perfect: two scores, both tens. Margo has more points than anyone because half the fair tasted her sweet potato swirl. A pie needs five scores to stand. Find me the winner before the custard sets!"

## Task

Return the name of the pie with the highest middle score. To find a pie's middle score, sort its scores: with an odd number of scores it is the one in the middle, and with an even number it is halfway between the two in the middle. Only pies with at least 5 scores qualify. On a tie, return the alphabetically first pie name. You will be working with the `pies` and `scores` tables.

## Tables

### `pies` (8 rows)

| column | type |
| --- | --- |
| pie_id | INTEGER |
| name | VARCHAR |
| baker | VARCHAR |

### `scores` (50 rows)

| column | type |
| --- | --- |
| score_id | INTEGER |
| pie_id | INTEGER |
| judge | VARCHAR |
| score | INTEGER |

## Data

The tables live in a DuckDB database: https://dbquacks.com/data/databases/weekly_202648_21_pie_off.duckdb

To query it outside the browser, attach it read-only:

```sql
ATTACH 'https://dbquacks.com/data/databases/weekly_202648_21_pie_off.duckdb' AS db (READ_ONLY);
USE db;
```

Play it in the browser: https://dbquacks.com/challenges/weekly/21

## Answer

The expected answer is not published. Submit on the page to have it checked.
