I know this is a popular topic, but I still haven't found what I was looking for. I would like to query one table
BOOKS_READ id user_id book_id
to format the leaderboard of users who have listed most books as read. When a user reads a book, the record corresponding to the book ID and user ID is registered in the books_read table.
Is it possible to rank the results of this query, starting from 1, and taking into account the links?
SELECT user_id, COUNT(*) AS book_count FROM books_read GROUP BY user_id ORDER BY book_count DESC LIMIT 10
In the case of communication, I would like to list the '=' sign in the results.
For instance,
rank user_id book_count =1 30 121 =1 17 121 2 101 119 =3 11 104 =3 91 104
Thanks so much for any help! I am not opposed to using PHP to handle some of them, but I am very interested in learning direct SQL solutions for such things :-)
source share