SQL PRACTICE PROBLEMS
DATABASE: Library Management System
TABLES:
1. books
- book_id (INT, PK)
- title (VARCHAR)
- author (VARCHAR)
- genre (VARCHAR)
- published_year (INT)
2. members
- member_id (INT, PK)
- name (VARCHAR)
- join_date (DATE)
- city (VARCHAR)
3. borrowings
- borrow_id (INT, PK)
- book_id (INT, FK -> books.book_id)
- member_id (INT, FK -> members.member_id)
- borrow_date (DATE)
- return_date (DATE)
PRACTICE PROBLEMS:
1. Write a query to list all books written by 'J.K. Rowling'.
2. Write a query to find all members who joined after 2023-01-01.
3. Write a query to find the number of books in each genre.
4. Write a query to list all borrowings along with member name and book title.
5. Write a query to find members who have borrowed more than 2 books.
6. Write a query to get the most borrowed book.
7. Write a query to list all books that haven't been borrowed yet.
8. Write a query to find members who borrowed books in the year 2024.
9. Write a query to calculate average number of books borrowed per member.
10. Write a query to list each member's most recently borrowed book.
BONUS:
- Create a view to show active borrowings (i.e., return_date IS NULL).
- Write a stored procedure to get borrowing history of a given member ID.