Professional Documents
Culture Documents
Member: member_no
Book: isbn
Borrowed: (member_no, isbn)
And the foreign keys are:
ii. Find the member number and name of each member in second year class:
π_member_no,_name (σ_class="second year" (Member))
iii. Find the member numbers which rented the book "DBMS" on '2-1-2019':
π_member_no (σ_isbn="DBMS" ∧ _date="2-1-2019" (Borrowed))
iv. Find the title of books which has borrowed by the member John:
π_title (σ_name="John" (Member ⨝ Borrowed ⨝ Book))
v. Find the member numbers which dont rent the "DBMS" book:
π_member_no (σ_isbn≠"DBMS" (Borrowed))
vi. Find the number of members who borrow more than five books:
π_count (γ_count (σ_count > 5 (γ_count (π_member_no,_count (Borrowed ⨝ π_count
(Book ⨝ π_member_no (Member)) ⨝ π_member_no (Member)))))
i. Find the member number and name of each member who has borrowed at least one
book published by "MCGraw-Hill":
SELECT DISTINCT member_no, name
FROM Member
WHERE member_no IN (
SELECT member_no
FROM Borrowed
JOIN Book ON Borrowed.isbn = Book.isbn
WHERE publisher = 'MCGraw-Hill'
);
ii. Create a new member name is 'Mozart' with member number '12121':
INSERT INTO Member (member_no, name, class)
VALUES ('12121', 'Mozart', 'N/A');
iii. Find the member whose name begin with the letter 'K':
SELECT * FROM Member
WHERE name LIKE 'K%';
iv. Find the total numbers of books which borrowed for each member:
SELECT member_no, COUNT(*)
FROM Borrowed
GROUP BY member_no;
vi. For each publisher, find the member number and name of each member who has
borrowed more than five books of that publisher:
SELECT publisher, m.member_no, m.name
FROM Borrowed
JOIN Book ON Borrowed.isbn = Book.isbn
JOIN Member m ON Borrowed.member_no = m.member_no
GROUP BY publisher, m.member_no, m.name
HAVING COUNT(*) > 5;
vii. Find the number of members who borrow more than the number of books borrowed
by Mozart:
SELECT COUNT(*)
FROM Member m
WHERE (SELECT COUNT(*) FROM Borrowed WHERE Borrowed.member_no = m.member_no) >
(SELECT COUNT(*) FROM Borrowed b JOIN Book ON b.isbn = Book.isbn WHERE
Book.publisher = 'MCGraw-Hill' AND b.member_no = m.member_no);