Skip to the content

Same book twice doesn't count

Problem

The library is giving a bookmark to every member who has borrowed more than one book. That means different books: someone who borrowed the same one twice has read one.

Show the member and how many different books they've borrowed, from the most to the fewest. Ties go in alphabetical order.

What it has to return

These rows, in this order

membertitles
Ann3
Luke2

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 member, COUNT(*)
FROM loans
GROUP BY member
Solve this challenge

It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.

More O(n) challenges

See all challenges →