Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

SQL Assignment6

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

PROJECT MEMBERS:

Muhammad Asif Jawed


BSCS 4(B) 16
Muhammad Sheraz
BSCS 4(B) - 18
SQL Queries Assignment

1. Which movies are supplied by "Joe's House of Video" or "Video


Warehouse"?

Select M.MovieName from Movies M, MovieSupplier MS, Suppliers S where


S.SupplierName = Joe's House of Video and M.MovieID = MS.MovieID
and S.SupplierID = MS.SupplierID
Union
Select M.MovieName from Movies M, MovieSupplier MS, Suppliers S where
S.SupplierName = "Video Warehouse" and M.MovieID = MS.MovieID and
S.SupplierID = MS.SupplierID

2. Which movie was rented for the longest duration (by any customer)?

Select M.MovieName from Rentals R, Movies M, Inventory I where


M.MovieID = I.MovieID and I.TapeID = R.TapeID and R.Duration >= ALL
(Select Duration from Rentals)

3. Which suppliers supply all the movies in the inventory? (Hint: first get a
list of the movie suppliers and all the movies in the inventory using the
cross product. Then find out which of these tuples are invalid.)

Select S.SupplierName from Suppliers where S.SupplierID not in (Select


MS.SupplierID, from MovieSupplier MS, Inventory I where not exists
(Select * from Inventory I, MovieSupplier MS where MS.MovieID =
I.MovieID and MS.SupplierID = MS.SupplierID and I.MovieID = I.MovieID))

4. How many movies in the inventory does each movie supplier supply?
That is, for each movie supplier, calculate the number of movies it
supplies that also happen to be movies in the inventory.
Select S.SupplierName, Count (Distinct S.MovieID) FROM Suppliers S,
MovieSupplier MS, Movies M where S.SupplierID = MS.SupplierID and
MS.MovieID = M.MovieID GROUP BY S.SupplierName

5. For which movies have more than 4 copies been ordered?

Select M.MovieName from Movies M, Orders O where O.MovieID =


M.MovieID GROUP BY M.MovieName HAVING SUM (Copies) > 4

6. Which customers rented "Fatal Attraction 1987" or rented a movie


supplied by "VWS Video"?

Select LastName from Customers C, Rentals R, Inventory I, Movies M


Where C.CustID = R.CustID and R.TapeID = I.TapeID and I.MovieID =
M.MovieID and M.MovieName LIKE "%Fatal Attraction 1987%"
UNION
Select LastName from Customers C, Rentals R, Inventory I, Movies M,
MovieSupplier MS, Suppliers S where C.CustID = R.CustID and R.TapeID =
I.TapeID and I.MovieID = M.MovieID and M.MovieID = MS.MovieID and
MS.SupplierID = S.SupplierID and S.SupplierName = "VWS Video"

7. For which movies are there more than 1 copy in our inventory? (Note that
the TapeID in inventory is different for different copies of the same
MovieID)

Select M.MovieName from Inventory I1, Inventory I2, Movies M


Where I1.MovieID = I2.MovieID and I1.TapeID <> I2.TapeID and I1.MovieID
= M.MovieID

8. Which customers rented movies for 5 days or more?


Select DISTINCT LastName from Customers C, Rentals R where C.CustID =
R.CustID and Duration >= 5

9. Which supplier has the cheapest price for the movie "Almost Angels
1962"?

Select S.SupplierName from Suppliers S, MovieSuppliers MS, Movies M


Where S.SupplierName = MS.SupplierName and MS.MovieID = M.MovieID
and M.MovieName LIKE "% Almost Angels 1962%" and price <= ALL
(SELECT price from MovieSuppliers MS, Movies M where M.MovieID =
MS.MovieID and M.MovieName LIKE "% Almost Angels 1962%")

10. Which movies aren't in the inventory?

Select M.MovieName from Movies M where M.MovieID NOT IN (SELECT


MovieID FROM Inventory)

You might also like