SQL Challenges · WEEKLY QUACK CHALLENGE!
THE GREAT PIE-OFF
Difficulty: medium
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 ha…
Your 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 |
Database: https://dbquacks.com/data/databases/weekly_202648_21_pie_off.duckdb
This page as markdown: https://dbquacks.com/challenges/weekly/21.md
More: practice SQL exercises online · SQL interview questions