CO226 Lab 6-Writing SQL Queries – Part II Solved

35.00 $ 17.50 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . zip solution files instantly, after Payment

Description

5/5 - (1 vote)

Lab Task:

Write the following SQL queries using MySQL, to retrieve the data from the database, you created in the previous lab.

  1. Write a nested query to list the details of the movies directed by a director,
    1. who is also a reviewer. (1 mark)
    2. who is not a reviewer. (1 mark)

 

  1. Write a nested query to list the details of the movie ratings,
    1. reviewed by the reviewer ‘Sarah Martinez’. (1 mark)
    2. not reviewed by the reviewer ‘Sarah Martinez’. (1 mark)

 

  1. Write a nested query to list the movie ids where each movie has some rating,
    1. less than to any of the ratings received by the movie which has a movie id equal to 103. (1 mark)
    2. less than or equal to any of the ratings received by the movie which has a movie id equal to 103. (1 mark)
    3. equal to any of the ratings received by the movie which has a movie id equal to 103. (1 mark)
    4. greater than to any of the ratings received by the movie which has a

movie id equal to 103. (1 mark)

  1. greater than or equal to any of the ratings received by the movie which has a movie id equal to 103. (1 mark)
  2. not equal to any of the ratings received by the movie which has a movie id equal to 103. (1 mark)

 

  1. 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)

 

  1. 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,
    1. a non-nested query. (5 marks)
    2. a non-correlated nested query. (5 marks)

 

  1. Find the titles of all movies that have no ratings. Write,
    1. non-correlated nested query. (5 marks)
    2. a correlated nested query. (5 marks)
  2. 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,
    1. a non-nested query. (5 marks)
    2. a non-correlated nested query. (5 marks)
    3. a correlated nested query. (5 marks)

 

  1. For each movie that has some rating, find A. the highest stars value received. (2 marks)
    1. the least stars value received. (2 marks)
    2. the average value of stars (2 marks)
    3. the sum of all the stars (2 marks)
    4. 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.

 

  1. Find the names of all the reviewers who have contributed three or more ratings.

Write,

  1. a non-nested query. (5 marks)
  2. a non-correlated nested query. (5 marks)
  3. a correlated nested query. (5 marks)

 

  1. 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)

 

  1. Remove all ratings where the movie’s year is before 1970 or after 2000. (5 marks)

 

  1. Remove all ratings where the rating date is NULL. (5 marks)

 

  1. Insert 5-star ratings by James Cameron for all movies in the database. Leave the review date as NULL. (5 marks)

 

  1. 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)