Recap - Books
Part of the Fundamentals section of Coddy's SQL journey — lesson 71 of 72.
Challenge
EasyAvailable tables and columns:
<strong>books</strong>:<strong>book</strong>,<strong>page</strong>,<strong>words</strong>
Books have many pages and each page has a lot of words.
In this challenge, we'll calculate cumulative metrics about these books up to each page. Follow these steps:
- First, calculate the following cumulative aggregations for each book up to each page:
- Total words (
total_words) - Maximum words (
max_words) - Minimum words (
min_words) - Average words (
avg_words)
- Total words (
- Then, for each page within a book, calculate the ratio:
(avg_words - min_words)/(total_words - min_words) - Finally, for each book:
- Densely rank the pages based on this ratio in ascending order (call this column
ratio_rank) - Order the results first by book and then by
ratio_rank
- Densely rank the pages based on this ratio in ascending order (call this column
Note: All aggregations (total, max, min, avg) should be cumulative, meaning they should consider all pages up to and including the current page for each book.
Try it yourself
All lessons in Fundamentals
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns