3910. Find Books with No Available Copies
My accepted SQL solution to LeetCode problem 3910, Find Books with No Available Copies, running in 488ms.
- Difficulty: Easy
- SQL
- Runtime 488ms
- Memory 0.0B
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
SQL
Accepted on LeetCode — runtime 488ms, memory 0.0B, accepted 2026-01-02.
SELECT
b.book_id,
b.title,
b.author,
b.genre,
b.publication_year,
COUNT(r.record_id) AS current_borrowers
FROM library_books b
JOIN borrowing_records r ON b.book_id = r.book_id
WHERE r.return_date IS NULL
GROUP BY b.book_id, b.title, b.author, b.genre, b.publication_year, b.total_copies
HAVING COUNT(r.record_id) = b.total_copies
ORDER BY current_borrowers DESC, b.title ASC;