0% found this document useful (0 votes)
3 views2 pages

SQL Practice Problems

The document outlines a Library Management System with three tables: books, members, and borrowings, detailing their respective fields. It includes a set of practice SQL problems aimed at querying the database, such as listing books by a specific author, finding members who joined after a certain date, and calculating average books borrowed per member. Additionally, it features a bonus section for creating a view of active borrowings and a stored procedure for retrieving a member's borrowing history.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

SQL Practice Problems

The document outlines a Library Management System with three tables: books, members, and borrowings, detailing their respective fields. It includes a set of practice SQL problems aimed at querying the database, such as listing books by a specific author, finding members who joined after a certain date, and calculating average books borrowed per member. Additionally, it features a bonus section for creating a view of active borrowings and a stored procedure for retrieving a member's borrowing history.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

You might also like