You are given a table Toppings that contains information about pizza toppings and their costs.
Table: Toppings
| Column Name | Type |
|---|---|
| topping_name | varchar |
| cost | decimal |
topping_name is the primary key for this table. Each row contains a topping name and its cost.
Problem:
- Calculate the total cost of all possible 3-topping pizza combinations
- Round the total cost to 2 decimal places
- Do not include combinations where a topping is repeated
- List toppings in alphabetical order within each combination
- Order results by total cost descending, then by topping combination ascending
Table Schema
| Column Name | Type | Description |
|---|---|---|
topping_name
PK
|
varchar | Name of the pizza topping (primary key) |
cost
|
decimal | Cost of the topping in dollars |
Input & Output
| topping_name | cost |
|---|---|
| Beef | 1.2 |
| Chicken | 1.3 |
| Cheese | 0.9 |
| Pepperoni | 1.5 |
| pizza | total_cost |
|---|---|
| Chicken,Cheese,Pepperoni | 3.7 |
| Beef,Chicken,Pepperoni | 4 |
| Beef,Cheese,Pepperoni | 3.6 |
| Beef,Chicken,Cheese | 3.4 |
With 4 toppings, we can create C(4,3) = 4 unique combinations. Each combination lists toppings alphabetically and shows the sum of their costs rounded to 2 decimal places. Results are ordered by total cost descending, then by pizza name ascending.
| topping_name | cost |
|---|---|
| Cheese | 1 |
| Pepperoni | 2 |
| Mushroom | 1.5 |
| pizza | total_cost |
|---|---|
| Cheese,Pepperoni,Mushroom | 4.5 |
With exactly 3 toppings, there is only one possible combination. The toppings are listed alphabetically (Cheese, Mushroom, Pepperoni becomes Cheese,Pepperoni,Mushroom) with total cost 4.50.
| topping_name | cost |
|---|---|
| Cheese | 1 |
| Pepperoni | 2 |
| pizza | total_cost |
|---|
With only 2 toppings available, it's impossible to create any 3-topping combinations. The result is an empty set.
Constraints
-
1 ≤ number of toppings ≤ 1000 -
topping_nameconsists of letters and spaces only -
0.01 ≤ cost ≤ 100.00 -
costhas at most 2 decimal places