Pizza Topping Combinations
Beginner Mode
Objective
Write a SQL query to list all possible 3-topping pizza combinations and calculate their total cost. Each combination must contain unique toppings listed in alphabetical order.
Table Schema:
- pizza_toppings
| Column | Type | Description |
|---|---|---|
| topping_name | VARCHAR | Name of the topping |
| ingredient_cost | DECIMAL | Cost of the topping |
Task Requirements:
- Generate all unique combinations of exactly 3 toppings
- Within each combination, toppings must appear in alphabetical order
- No topping can appear more than once in a combination
- Concatenate the 3 toppings into a single string separated by
', ' - Calculate the total cost by summing the 3 ingredient costs
- Sort by total cost descending, then by the pizza string alphabetically
Output columns: pizza, total_cost
Examples
Example 1:
Output:
Input:
| pizza_toppings | |
|---|---|
| ingredient_cost | topping_name |
| 1.5 | Bacon |
| 0.75 | Mushrooms |
| 0.5 | Onions |
| 1.25 | Pepperoni |
| pizza | total_cost |
|---|---|
| Bacon, Mushrooms, Pepperoni | 3.5 |
| Bacon, Onions, Pepperoni | 3.25 |
| Bacon, Mushrooms, Onions | 2.75 |
| Mushrooms, Onions, Pepperoni | 2.5 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
DoorDash