Docsity

5 Questions for Assignment 3 - Database System | CIT 381, Assignments of Deductive Database Systems

Toggle sidebar
bg1
Jhomer Recometa
11/13/2004
CIT 381
HW 3
1. Which parts of the SQL SELECT statement are used to specify the relational
operations projection, selection, and join?
โ€“ A projection operation produces a result table with only some of the
columns of its input table. In a SQL statement, this is represented by the
SELECT and FROM parameters.
โ€“ A selection operation produces a result table with all of the columns of the
input table and only those rows of its input table that satisfy some criteria.
In a SQL statement, this is represented by the WHERE statement.
โ€“ A join operation produces a result table by combining the columns of two
input tables. In a SQL Statement the join is produced with a combination
of the FROM, JOIN and ON statements.
2. Write an SQL query to find out which movies have been previously rented.
Include in your output title, accountId, dateRented, dateReturned, and cost.
Order the results by title (ascending) and then dateRented (descending) for each
title.
SELECT m.title, p.accountId, p.dateRented, p.dateReturned, p.cost
FROM (Video v INNER JOIN Movie m ON v.movieId = m.movieId)
INNER JOIN PreviousRental p ON p.videoId = v.videoId
ORDER BY m.title, p.dateRented DESC;
Movies โ€“ Previously Rented
title accountId dateRented dateReturned cost
Animal House 201 1/14/2002 1/24/2002 $3.35
Annie Hall 101 1/15/2002 1/15/2002 $0.99
Annie Hall 201 12/9/2001 12/14/2001 $3.99
Annie Hall 102 12/1/2001 12/3/2001 $2.49
Annie Hall 101 1/13/2001 1/4/2001 $1.99
Duck Soup 111 1/1/2002 1/4/2002 $3.95
The Thirty-Nine Steps 101 12/9/2001 12/10/2001 $2.49
The Thirty-Nine Steps 111 12/4/2001 12/6/2001 $2.49
pf2

Partial preview of the text

Download 5 Questions for Assignment 3 - Database System | CIT 381 and more Assignments Deductive Database Systems in PDF only on Docsity!

Jhomer Recometa 11/13/ CIT 381 HW 3

  1. Which parts of the SQL SELECT statement are used to specify the relational operations projection , selection , and join? - A projection operation produces a result table with only some of the columns of its input table. In a SQL statement, this is represented by the SELECT and FROM parameters. - A selection operation produces a result table with all of the columns of the input table and only those rows of its input table that satisfy some criteria. In a SQL statement, this is represented by the WHERE statement. - A join operation produces a result table by combining the columns of two input tables. In a SQL Statement the join is produced with a combination of the FROM , JOIN and ON statements.
  2. Write an SQL query to find out which movies have been previously rented. Include in your output title , accountId, dateRented, dateReturned , and cost. Order the results by title (ascending) and then dateRented (descending) for each title. SELECT m.title, p.accountId, p.dateRented, p.dateReturned, p.cost FROM (Video v INNER JOIN Movie m ON v.movieId = m.movieId) INNER JOIN PreviousRental p ON p.videoId = v.videoId ORDER BY m.title, p.dateRented DESC; Movies โ€“ Previously Rented title accountId dateRented dateReturned cost Animal House 201 1/14/2002 1/24/2002 $3. Annie Hall 101 1/15/2002 1/15/2002 $0. Annie Hall 201 12/9/2001 12/14/2001 $3. Annie Hall 102 12/1/2001 12/3/2001 $2. Annie Hall 101 1/13/2001 1/4/2001 $1. Duck Soup 111 1/1/2002 1/4/2002 $3. The Thirty-Nine Steps 101 12/9/2001 12/10/2001 $2. The Thirty-Nine Steps 111 12/4/2001 12/6/2001 $2.
  1. Write an SQL query to find out which videos customer 101 previously has rented and when they were returned. Include in your output videoId, title, dateReturned, but label them "Video", "Movie", "Date Returned". Sort your results by "Date Returned" ascending. SELECT p.videoId AS [Video], m.title AS [Movie], p.dateReturned AS [Date Returned] FROM (Movie m INNER JOIN Video v ON m.movieId = v.movieId) INNER JOIN PreviousRental p ON p.videoId = v.videoId WHERE p.accountId = 101 ORDER BY p.dateReturned; Videos For Customer 101 Video Movie Date Returned 112 Annie Hall 1/4/ 101 The Thirty-Nine Steps 12/10/ 113 Annie Hall 1/15/
  2. Write an SQL query to determine how many videos (not distinct), the average cost, and the total cost of the previously rented videos for all customers who live in Apopka, Florida. Label the output "Number of Videos", "Average Cost", "Total Cost". SELECT COUNT(p.videoId) AS [Number of Videos], AVG(p.cost) AS [Average Cost], SUM(p.cost) AS [Total Cost] FROM PreviousRental p INNER JOIN Customer c ON p.accountId = c.accountId WHERE c.city = 'Apopka' AND c.state = 'FL'; Previously rented videos โ€“ Apopka, FL Number of Videos Average Cost Total Cost 5 $2.38 $11.