数据库系统概念第三章
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
SQL Exercise 1
Movie ( mID, title, year, director ) Reviewer ( rID, name ) Rating ( rID, mID, stars, ratingDate )
Question 5 Write a query to return the ratings data in a more readable format: reviewer name, movie title, stars, and ratingDate. Also, sort the data, first by reviewer name, then by movie title, and lastly by number of stars.
SQL Exercise 1
Movie ( mID, title, year, director ) Reviewer ( rID, name ) Rating ( rID, mID, stars, ratingDate )
Question 4 Some reviewers didn't provide a date with their rating. Find the names of all reviewers who have ratings with a NULL value for the date.
a certain name.
Rating ( rID, mID, stars, ratingDate ) English: The reviewer rID gave the movie mID a
number of stars rating (1-5) on a certain ratingDate.
SQL Exercise 1
Movie ( mID, title, year, director ) Reviewer ( rID, name ) Rating ( rID, mID, stars, ratingDate )
Question 7 For each movie, find the highest number of stars that movie received as a rating. Return the movie title and number of stars. Sort by movie title.
SQL Exercise 1
Movie ( mID, title, year, director ) Reviewer ( rID, name ) Rating ( rID, mID, stars, ratingDate )
Question 12 For all movies that have an average rating of 4 stars or higher, add 25 to the release year. (Update the existing tuples; don't insert new tuples.)
SQL Exercise 1
Movie ( mID, title, year, director ) Reviewer ( rID, name ) Rating ( rID, mID, stars, ratingDate )
Question 3 Find the titles of all movies that have no ratings
Question 4 Some reviewers didn't provide a date with their rating. Find the names of all reviewers who have ratings with a NULL value for the date.
select title from movie except select title from movie,rating where movie.mid=rating.mid
Solutions for SQL Exercise 1
Movie ( mID, title, year, director ) Reviewer ( rID, name ) Rating ( rID, mID, stars, ratingDate )
SQL Exercise 1
Movie ( mID, title, year, director ) Reviewer ( rID, name ) Rating ( rID, mID, stars, ratingDate )
Question 2 Find all years that have a movie that received a rating of 4 or 5, and sort them in increasing order.
Solutions for SQL Exercise 1
Movie ( mID, title, year, director ) Reviewer ( rID, name ) Rating ( rID, mID, stars, ratingDate )
Question 3 Find the titles of all movies that have no ratings.
SQL Exercise 1
Movie ( mID, title, year, director ) Reviewer ( rID, name ) Rating ( rID, mID, stars, ratingDate )
Question 1 Find the titles of all movies directed by Steven Spielberg.
Question 2 Find all years that have a movie that received a rating of 4 or 5, and sort them in increasing order.
select distinct year from movie,rating where movie.mid=rating.mid and stars in (4,5) order by year
select title from movie where director='Steven Spielberg'
Solutions for SQL Exercise 1
Movie ( mID, title, year, director ) Reviewer ( rID, name ) Rating ( rID, mID, stars, ratingDate )
SQL Exercise 1
Movie ( mID, title, year, director ) Reviewer ( rID, name ) Rating ( rID, mID, stars, ratingDate )
Question 6 For all cases where the same reviewer rated the same movie twice and gave it a higher rating the second time, return the reviewer's name and the title of the movie.
SQL Exercise 1
Movie ( mID, title, year, director ) Reviewer ( rID, name ) Rating ( rID, mID, stars, ratingDate )
Question 11 Insert 5-star ratings by James Cameron for all movies in the database. Leave the review date as NULL.
Solutions
Solutions for SQL Exercise 1
Movie ( mID, title, year, director ) Reviewer ( rID, name ) Rating ( rID, mID, stars, ratingDate )
Question 1 Find the titles of all movies directed by Steven Spielberg.
SQL Exercise 1
Movie ( mID, title, year, director ) Reviewer ( rID, name ) Rating ( rID, mID, stars, ratingDate )
Question 10 Add the reviewer Roger Ebert to your database, with an rID of 209.
Principles of Database Systems
SQL Exercise 1
SQL Exercise 1
You've started a new movie-rating website, and you've been collecting data on reviewers' ratings of various movies. There's not much data yet, but you can still try out some interesting queries. Here's the schema:
SQL Exercise 1
Movie ( mID, title, year, director ) Reviewer ( rID, name ) Rating ( rID, mID, stars, ratingDate )
Question 8 For each movie, return the title and the 'rating spread', that is, the difference between highest and lowest ratings given to that movie. Sort by rating spread from highest to lowest, then by movie title.
SQL Exercise 1
Movie ( mID, title, year, director ) English: There is a movie with ID number mID,
a title, a release year, and a director.
Reviewer ( rID, name ) English: The reviewer with ID number rID has
SQL Exercise 1
Movie ( mID, title, year, director ) Reviewer ( rID, name ) Rating ( rID, mID, stars, ratingDate )
Question 9 Find the difference between the average rating of moቤተ መጻሕፍቲ ባይዱies released before 1980 and the average rating of movies released after 1980. (Make sure to calculate the average rating for each movie, then the average of those averages for movies before 1980 and movies after. Don't just calculate the overall average rating before and after 1980.)