Pizza Topping Combinations
DoorDash 🧠 Hard SQL
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:

Input:

pizza_toppings
ingredient_costtopping_name
1.5Bacon
0.75Mushrooms
0.5Onions
1.25Pepperoni

Output:
pizzatotal_cost
Bacon, Mushrooms, Pepperoni3.5
Bacon, Onions, Pepperoni3.25
Bacon, Mushrooms, Onions2.75
Mushrooms, Onions, Pepperoni2.5
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →