0% found this document useful (0 votes)
2 views

SQL- Practice Problem3

The document outlines practice problems for a Database Systems course, focusing on SQL queries related to two databases: a LIBRARY database and a Movie database. It includes a series of specific SQL questions aimed at retrieving various data points such as library branch details, book loans, and movie production costs. The problems are designed to test students' understanding of relational database concepts and SQL syntax.

Uploaded by

tfaizanvr
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)
2 views

SQL- Practice Problem3

The document outlines practice problems for a Database Systems course, focusing on SQL queries related to two databases: a LIBRARY database and a Movie database. It includes a series of specific SQL questions aimed at retrieving various data points such as library branch details, book loans, and movie production costs. The problems are designed to test students' understanding of relational database concepts and SQL syntax.

Uploaded by

tfaizanvr
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

National University of Computer and Emerging Sciences, Lahore Campus

Course: Database Systems


Program: BS(Computer Science)
Instructor: Muhammad Ishaq Raza

Practice Problem: SQL (3)

Question 1: Consider the LIBRARY relational database schema given below which is used to keep track of books,
borrowers, and book loans.

Book (book_id, title, publisher_name)


Book_Author (book_id, author_name)
Publisher(name, address, phone)
Book_Copies (book_id, branch_id, no_of_copies)
Book_loan (book_id, branch_id, card_no, date_out, due_date)
Library_Branch (branch_id, name, address)
Borrower (Card_no, name, address, phone, age, gender)

Write down SQL statements for the following queries:

i. List complete details of all library branches.


ii. List all the books reserved by the borrowers aged less than 30 years.
iii. Find the library branches which do not have any copy of book whose book_id is EE1234.
iv. Find the library branch which has the highest number of total books than all other branches.
v. Find out the total number of copies of the book titled Emma are possessed by each library branch?
vi. For each library branch, retrieve the branch name and the total number of books loaned out from that
branch.
vii. Retrieve the names of borrowers who have not borrowed books from library branch that is in Faisalabad.
viii. Retrieve the names of the books that are loaned by borrower with card no 1000 only.
ix. How many library branches are there?

Page 1 of 2
Question 2. Write down SQL statements for the following queries.

Consider the following Movie database for all the questions; for simplicity assume that the title of a movie is unique.
The length of the movie is its running time in minutes, and net worth of the studio is its monetary value in dollars.
The underlined attributes are part of the primary key. Foreign keys are studioName, actorSSN, and movieTitle.

Movie (Title, Year, Length, StudioName, ProductionCost)

StarsIn (ActorSSN, MovieTitle)

Actor (SSN, FirstName, LastName, Age, Gender, Address)

Studio (Name, Address, Networth)

i. List all movies made during time period 1970-1990 with a production cost below $7500000, in ascending order
of cost.
ii. List the movies for which no production cost has been specified.
iii. Find the minimum, maximum and average production cost of movies made by Fox Studio?
iv. List the number of movies produced by each studio, consider only those studios that have net worth of at least
10 million US dollars and produced at least 5 movies.
v. Find those actors who starred in at least 3 movies made in 1990-1995 by studios based in California.
vi. List those actor SSN pairs whose last name is the same.
vii. List the name of those actors who worked together in the same movie.
viii. List those actors who have not yet starred in any movie.
ix. Display the name and age of all actors who have appeared in any movie made by Fox Studio but not in the movie
made by Universal Studios.
x. Display the name and age of all actresses who have starred in at least 2 movies made by Universal Studios as
well as in at least 3 movies made by 21st Century Fox.
xi. List all Studios which have net worth greater than Universal Studios’.
xii. List those movie titles along with the studio name in which Actor Tom Hanks did not star. (Note: Name is
divided into first name and last name in Actor table)
xiii. List those actresses who costarred in at least one movie in which actor Harrison Ford has starred.
xiv. List all those studios that have made more movies than Universal Studios or 21st Century Fox during 1990-
2000.
xv. Find those actresses who have worked in more movies than all actors.
xvi. Find the actresses who have worked on all the movies produced by ‘Disney’ studio in year 2000.

Page 2 of 2

You might also like