Professional Documents
Culture Documents
(iii) Demonstrate how you add a new text book to the database and make this book be
adopted by some department.
INSERT into text values(105,'Software','Sapna','Naidu');
INSERT into book_adoption values(201,5,105);
(iv) Produce a list of textbooks (include Course #, Book-ISBN, Book-title) in the
alphabetical order for courses offered by the ‘CS’ department that use more than two
books.
SELECT c.course_code, b.book_isbn, t.book_title
FROM course c, book_adoption b, text t
WHERE cname='CSE' and c.course_code= b.course_code and
b.book_isbn= t.book_isbn and (SELECT count(b1.book_isbn)
FROM book_adoption b1 WHERE c.course_code= b.course_code)>2
ORDER BY t.book_title ASC;
(v) List any department that has all its adopted books published by a specific publisher.
SELECT distinct c.course_code,c.cname
FROM course c
WHERE c.course_code in (SELECT c.course_code
FROM course c, book_adoption b,text t
where t.publisher='GK')
and c.course_code NOT in
(SELECT c1.course_code
FROM course c1, book_adoption b1,text t1
where t1.publisher!='GK');
(vi) List the regno and name of the students who have enrolled for maximum number of
courses.
SELECT s.regno, s.name, count(e.course_code) as No_Of_Courses
FROM enroll e, student s
WHERE e.regno=s.regno
GROUP by s.regno, s.name
HAVING COUNT(e.course_code)>= all(SELECT COUNT(e1.course_code)
FROM enroll e1, student s1
WHERE e1.regno=s1.regno
GROUP BY e1.course_code);
OR
select * FROM
(
SELECT s.regno, s.name, count(e.course_code) as No_Of_Courses
FROM enroll e, student s
WHERE e.regno=s.regno
GROUP by s.regno, s.name
ORDER BY count(e.course_code) DESC
)
WHERE rownum=1;
(vii) List the text books which have not been adopted by any of the course.
SELECT DISTINCT t.book_isbn
FROM text t
MINUS
SELECT b.book_isbn
FROM book_adoption b, course c
WHERE c.course_code= b.course_code;
(viii) List the book-ISBNs which have been adopted by both Datastructures and
Algorithms.
SELECT b.book_isbn
FROM book_adoption b, course c
WHERE c.course_code= b.course_code and c.cname='Datastuctures'
UNION
SELECT b.book_isbn
FROM book_adoption b, course c
WHERE c.course_code= b.course_code and c.cname='Algorithms';
(ix) List the Book-ISBN and title of book which have been adopted by both Datastructures
and Algorithms.
(SELECT b.book_isbn, t.book_title
FROM book_adoption b, course c, text t
WHERE c.course_code= b.course_code and b.book_isbn= t.book_isbn
and c.cname='ISE')
UNION
(SELECT b.book_isbn, t.book_title
FROM book_adoption b, course c, text t
WHERE c.course_code= b.course_code and b.book_isbn= t.book_isbn
and c.cname='CSE');
(x) List the departments that have all its adopted books published by a specific publisher or
departments that have adopted maximum number of books.
SELECT b.course_code, count(*)
FROM book_adoption b
GROUP BY b.course_code
HAVING count(*)>=all(SELECT COUNT(*)
FROM book_adoption b
GROUP BY b.course_code);
(xi) list the publisher in ascending alphabetical order along with descending alphabetical
order of Book-ISBN,who have published minimum TWO books.
SELECT t.publisher,t.book_isbn, t.book_title
FROM text t
HAVING COUNT(t1.book_isbn)>=2 )
(xiii) List the courses that have minimum enrollments with maximum books being adopted.
(xiv) List the Course No, Title of the book adopted and Author name if author has written
more than ONE book.