Description
Lab Task:
Write the following SQL queries using MySQL, to retrieve the data from the database, you created in the previous lab.
- Write a nested query to list the details of the movies directed by a director,
- who is also a reviewer. (1 mark)
- who is not a reviewer. (1 mark)
- Write a nested query to list the details of the movie ratings,
- reviewed by the reviewer ‘Sarah Martinez’. (1 mark)
- not reviewed by the reviewer ‘Sarah Martinez’. (1 mark)
- Write a nested query to list the movie ids where each movie has some rating,
- less than to any of the ratings received by the movie which has a movie id equal to 103. (1 mark)
- less than or equal to any of the ratings received by the movie which has a movie id equal to 103. (1 mark)
- equal to any of the ratings received by the movie which has a movie id equal to 103. (1 mark)
- greater than to any of the ratings received by the movie which has a
movie id equal to 103. (1 mark)
- greater than or equal to any of the ratings received by the movie which has a movie id equal to 103. (1 mark)
- not equal to any of the ratings received by the movie which has a movie id equal to 103. (1 mark)
- Write a nested query to list the reviewer ids who has the same (movie id, stars) combination on some movie which has a rating date equal to 2011-01-12. (5 marks)
- Find all the years that have a movie that received a rating of 4 or 5 and sort them in increasing order of the year. Write,
- a non-nested query. (5 marks)
- a non-correlated nested query. (5 marks)
- Find the titles of all movies that have no ratings. Write,
- non-correlated nested query. (5 marks)
- a correlated nested query. (5 marks)
- Some reviewers did not provide a date with their rating. Find the names of all reviewers who have a NULL value for the date. Write,
- a non-nested query. (5 marks)
- a non-correlated nested query. (5 marks)
- a correlated nested query. (5 marks)
- For each movie that has some rating, find A. the highest stars value received. (2 marks)
- the least stars value received. (2 marks)
- the average value of stars (2 marks)
- the sum of all the stars (2 marks)
- the number of times each movie was rated. (2marks)
In each of the above cases, return the movie title and asked stars value. Sort the results by movie title.
- Find the names of all the reviewers who have contributed three or more ratings.
Write,
- a non-nested query. (5 marks)
- a non-correlated nested query. (5 marks)
- a correlated nested query. (5 marks)
- List the movie titles and average ratings, from the highest-rated to lowest-rated. If two or more movies have the same average rating, list them in alphabetical order. (5 marks)
- Remove all ratings where the movie’s year is before 1970 or after 2000. (5 marks)
- Remove all ratings where the rating date is NULL. (5 marks)
- Insert 5-star ratings by James Cameron for all movies in the database. Leave the review date as NULL. (5 marks)
- For all movies that have an average rating of 4 stars or higher, add 25 to the release year. (Update the existing tuples. Do not insert new tuples). (5 marks)