NATURAL JOIN
Pissa, the ever-expanding pizza delivery enterprise, has a new challenge for you. They're interested in discovering which type of pizza generates the most revenue.
Here is the pizza
schema for reference:
Identify the single top-selling pizza category using your knowledge of NATURAL JOIN
.
This exercise is part of the course
Introduction to Snowflake SQL
Exercise instructions
- Get the
category
from the appropriate table. NATURAL JOIN
thepizza_type
table.- Group the records by
category
from thept
(pizza_type
) table. - Order the details by
total_revenue
in descending order and limit to a single record, so that only the top revenue-generating pizza is returned.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
SELECT
-- Get the pizza category
___,
SUM(p.price * od.quantity) AS total_revenue
FROM order_details AS od
NATURAL JOIN pizzas AS p
-- NATURAL JOIN the pizza_type table
___ pizza_type AS pt
-- GROUP the records by category
___
-- ORDER by total_revenue and limit the records
___
___