Menu
Coddy logo textTech

Recap - Books

Part of the Fundamentals section of Coddy's SQL journey — lesson 71 of 72.

challenge icon

Challenge

Easy

Available 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:

  1. 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)
  2. Then, for each page within a book, calculate the ratio: (avg_words - min_words)/(total_words - min_words)
  3. 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

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