Kodewick
Start learning →
Basic←→0 / 70

Average loan

#048BasicNULLAggregates3 min

In the loans table, days is how many days a book was out; for books not back yet, days is empty (NULL). Work out the average of days (leaving the empty ones out), rounded to 1 decimal place with ROUND(…, 1).

The tables
books
idtitleauthorgenrepagesyear
1The Night GardenMia Lanestory2102015
2Stars for KidsTom Hartscience962020
3Lost at SeaMia Lanestory3402011
4Easy BreadRosa Bellfood1282019
5The Bug BookTom Hartscience642022
6Soup DaysRosa Bellfood1502008
7The Red KiteAnn Colestory1802021
8Rocks and RiversAnn Colescience2202017
8 rows
loans
idbook_idreaderdays
11Leo14
22Nora7
31SamNULL
44Leo21
55NoraNULL
63Ivy10
72Sam5
87Ivy12
8 rows
query.sql
-- your code here: ROUND(AVG(days), 1) for the average number of days
SELECT days
FROM loans;
Ctrl + Enter runs too
Result

Run shows what your query gives. When it looks right, Submit.