The last night counts too
- O(log n) · Easy
- Free
- SQL
- operations
- conditionals
Problem
A member reads 30 pages a night, not one more, and before borrowing a book wants to know how many nights it will last. The night with only a few pages left is a night too: "Maps of Salt," at 340, lasts 12 nights and not 11. And "The Lighthouse," at exactly 210, lasts 7 and not 8. Show the title, the pages, and the nights for each book, in that order.
What it has to return
These rows, in any order
| title | pages | nights |
|---|---|---|
| The Lighthouse | 210 | 7 |
| Maps of Salt | 340 | 12 |
| The Blue House | 180 | 6 |
| Three Winters | 420 | 14 |
| Loose Leaves | 95 | 4 |
| The Train South | 260 | 9 |
| Long Night | 310 | 11 |
| Short Stories | 120 | 4 |
This is what comes out with the data in the practice database this challenge uses. The column names don’t count, so name yours however you like: what counts is how many there are and the order they come in. Besides this one, the challenge has hidden tests with other data that are revealed when you submit your solution.
You start with this
SQL
SELECT title, pages,
pages / 30 AS nights
FROM books;It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.