Subquery's
Pissa, het snelgroeiende pizzabezorgbedrijf, maakt nu gebruik van jouw expertise om trends te ontdekken.
Ze willen het pizziaanbod stroomlijnen door underperformende pizza’s te identificeren. Jouw taak is om de pizzatypes te vinden die minder vaak zijn besteld dan het gemiddelde over alle types.
Deze oefening maakt deel uit van de cursus
Introductie tot Snowflake SQL
Oefeninstructies
- Vul de subquery in om de
AVGvantotal_quantityte vinden. - Bereken
total_quantitybinnen de subquery. - Geef de subquery de alias
subquery.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
SELECT pt.name,
pt.category,
SUM(od.quantity) AS total_orders
FROM pizza_type pt
JOIN pizzas p
ON pt.pizza_type_id = p.pizza_type_id
JOIN order_details od
ON p.pizza_id = od.pizza_id
GROUP BY ALL
HAVING SUM(od.quantity) < (
-- Calculate AVG of total_quantity
SELECT ___(___)
FROM (
-- Calculate total_quantity
SELECT ___(___.___) AS total_quantity
FROM pizzas p
JOIN order_details od
ON p.pizza_id = od.pizza_id
GROUP BY p.pizza_id
-- Alias as subquery
) ___
)