Querying the snowflake schema
Imagine that you didn't have the data warehouse set up. Instead, you'll have to run this query on the company's operational database, which means you'll have to rewrite the previous query with the following snowflake schema:
The tables in this schema have been loaded. Remember, our goal is to find the amount of money made from the novel genre in each state.
This is a part of the course
“Database Design”
Exercise instructions
- Select
state
from the appropriate table and the totalsales_amount
. - Complete the two JOINS to get the
genre_id
's. - Complete the three JOINS to get the
state_id
's. - Conditionally select for books with the
genre
novel
. - Group the results by state.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
-- Output each state and their total sales_amount
SELECT ___.___, ___(___)
FROM ___
-- Joins for genre
JOIN dim_book_sf on ___.___ = ___.___
JOIN dim_genre_sf on ___.___ = ___.___
-- Joins for state
JOIN ___ on ___.store_id = ___.store_id
JOIN ___ on ___.city_id = ___.city_id
JOIN ___ on ___.state_id = ___.state_id
-- Get all books with in the novel genre and group the results by state
WHERE
___.___ = '___'
GROUP BY
___.___;
This exercise is part of the course
Database Design
Learn to design databases in SQL to process, store, and organize data in a more efficient way.
In this chapter, you will take your data modeling skills to the next level. You'll learn to implement star and snowflake schemas, recognize the importance of normalization and see how to normalize databases to different extents.
Exercise 1: Star and snowflake schemaExercise 2: Running from star to snowflakeExercise 3: Adding foreign keysExercise 4: Extending the book dimensionExercise 5: Normalized and denormalized databasesExercise 6: Querying the star schemaExercise 7: Querying the snowflake schemaExercise 8: Updating countriesExercise 9: Extending the snowflake schemaExercise 10: Normal formsExercise 11: Converting to 1NFExercise 12: Converting to 2NFExercise 13: Converting to 3NFWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.