Given a library database, write SQL to answer the following:
-
Count the number of books that are currently not returned (i.e., still checked out) and are in good condition.
-
Among those currently not returned and in good condition, compute the percentage that have been renewed more than 2 times (use that subset as the denominator).
-
Return the top 3 book titles or IDs that have more than 10 copies and the longest total lending time across all their loans (sum of loan durations).
-
Find the member–referrer pair with the greatest difference in the number of reservations they have made, and return the pair and the difference.