CommencerCommencer gratuitement

Top meals by cost

Alice from Finance wants to know what Delivr's top 5 meals are by overall cost; in other words, Alice wants to know the 5 meals that Delivr has spent the most on for stocking.

You're provided with an aggregate query; you'll need to fill in the blanks to get the output Alice needs.

Note: Recall that in the meals table, meal_price is what the user pays Delivr for the meal, while meal_cost is what Delivr pays its eateries to stock this meal.

Cet exercice fait partie du cours

Analyzing Business Data in SQL

Afficher le cours

Instructions

  • Calculate cost per meal ID.
  • Set the LIMIT to 5.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

SELECT
  -- Calculate cost per meal ID
  ___,
  ___ AS cost
FROM meals
JOIN stock ON meals.meal_id = stock.meal_id
GROUP BY meals.meal_id
ORDER BY cost DESC
-- Only the top 5 meal IDs by purchase cost
LIMIT ___;
Modifier et exécuter le code