AnalystPath

Lopsided Recipes

SQLMediumMid level~15 min

Problem

Table: `RecipeLines`

```text
+--------------+------+
| Column Name | Type |
+--------------+------+
| recipe_id | int |
| ingredient_id| int |
| grams | int |
+--------------+------+
(recipe_id, ingredient_id) is the primary key for this table.
Each row gives how many grams of one ingredient a recipe uses.
```

A recipe is called **lopsided** when its single heaviest ingredient (its maximum grams) is strictly greater than the largest average-grams figure found among all recipes, where each recipe's average is taken over its own ingredients, and the comparison includes the recipe itself.

Write a solution to find the `recipe_id` of every lopsided recipe.

Return the result table in any order.

Tables

Example rows — the live problem includes the full dataset.

RecipeLines
recipe_idingredient_idgrams
110100
111200
112300

Expected output

Your answer should return 1 row with the columns recipe_id.

Starter code (SQL)

SELECT *
FROM RecipeLines;

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