top of page

Post analysis on IMDB data by RSVP Movies | Database Assignment and Homework Help

Updated: May 27, 2022


Requirement

Query 1:

Most of the movies were produced in the month of March with an average of about 2300 movies per year.


Query 2:

Drama was the most popular genre with 4285 number of movies and an avg duration of 106.7746. RSVP movies can focus on this genre for its future films. Action and Thriller genres also hold potential.


Query 3:

Most of the movies were rated between 6-8 on a median rating scale. Aiming for 8+ on a median rating will increase chances of a superhit movie.


Query 4:

Dream warrior Pictures and National Theatre Live had produced highest rated films. Star Cinema and Twentieth Century Fox are also good contenders due to high number of multilingual movies as the movie will be for Indian audience primarily.


Query 5:

Top directors observed from the analysis are James Mangold, Anthony Russo, Joe Russo and Soubin Shahir. With the later 3 tied at #2 spot. RSVP can have its future projects with them.


Query 6:

Mammooty and Mohanlal are the top actors with highest number of rating.


Query 7:

Taapsee Pannu can be chosen as actress as she is on the top of the list with average rating 7.74 and maximum votes.


Query 8:

Marvel Studios(1st) Twentieth Century Fox(2nd) & Warner Bros.(3rd) can be chosen as its Global Partners as number of votes received is maximum of their movies.


Query 9:

In India, Vijay Sethupati can be focused on as he his popular here.

10.Star Cinema and Twentieth Century Fox are the top two production houses that have produced the highest number of hits (median rating >= 8) among multilingual movies



Creating Tables:

/******************************************************************************************

/ Queries to create a smaller version of IMDB database

/ For SQL Assignment from UpGrad. Created by Shreyas M

/*****************************************************************************************/


-- Creating and using the database 
DROP DATABASE IF EXISTS imdb;
CREATE DATABASE imdb;

USE imdb;
-- Creating the structure of various tables in the database
DROP TABLE IF EXISTS movie;
CREATE TABLE movie
 (
  id VARCHAR(10) NOT NULL,
  title VARCHAR(200) DEFAULT NULL,
  year INT DEFAULT NULL,
  date_published DATE DEFAULT null,
  duration INT,
  country VARCHAR(250),
  worlwide_gross_income VARCHAR(30),
  languages VARCHAR(200),
  production_company VARCHAR(200),
  PRIMARY KEY (id)
);

DROP TABLE IF EXISTS genre;
CREATE TABLE genre
 (
	movie_id VARCHAR(10),
    genre VARCHAR(20),
	PRIMARY KEY (movie_id, genre)
);

DROP TABLE IF EXISTS director_mapping;
CREATE TABLE director_mapping	
 (
	movie_id VARCHAR(10),
    name_id VARCHAR(10),
	PRIMARY KEY (movie_id, name_id)
);

DROP TABLE IF EXISTS role_mapping;
CREATE TABLE role_mapping
 (
	movie_id VARCHAR(10) NOT NULL,
    name_id VARCHAR(10) NOT NULL,
    category VARCHAR(10),
	PRIMARY KEY (movie_id, name_id)
);
	
DROP TABLE IF EXISTS names;
CREATE TABLE names
 (
  id varchar(10) NOT NULL,
  name varchar(100) DEFAULT NULL,
  height int DEFAULT NULL,
  date_of_birth date DEFAULT null,
  known_for_movies varchar(100),
  PRIMARY KEY (id)
);

DROP TABLE IF EXISTS ratings; 
CREATE TABLE ratings
(
	movie_id VARCHAR(10) NOT NULL,
	avg_rating DECIMAL(3,1),
	total_votes INT,
	median_rating INT,
    PRIMARY KEY (movie_id)
);


Inserting Values

-- Inserting values into movie
INSERT INTO movie
VALUES
('tt0012494','Der müde Tod',2017,'2017-06-09',97,'Germany','$ 12156','German','Decla-Bioscop AG'),('tt0038733','A Matter of Life and Death',2017,'2017-12-08',104,'UK','$ 124241','English, French, Russian','The Archers'),('tt0361953','The Nest of the Cuckoo Birds',2017,'2017-10-16',81,'USA',null,'English','Bert Williams Motion Pictures and Distributor'),('tt0235166','Against All Hope',2017,'2017-10-20',90,'USA',null,'English',null),('tt0337383','Vaikai is Amerikos viesbucio',2017,'2017-03-09',88,'Soviet Union',null,'Lithuanian);

-- Inserting values into genre

INSERT INTO genre
VALUES
('tt0012494','Thriller'),('tt0012494','Fantasy'),('tt0012494','Drama'),('tt0038733','Fantasy'),('tt0038733','Drama'),('tt0038733','Comedy'),('tt0060908','Comedy'),('tt0060908','Drama'),('tt0069049','Drama'),('tt0071145','Drama'),('tt0082620','Horror'),('tt0083907','Horror'),('tt0085953','Horror'),('tt0095857','Drama'),('tt0095857','Comedy'),('tt0097268','Drama'),('tt0100275','Fantasy'),('tt0100275','Drama'),('tt0100275','Comedy'),('tt0116851','Romance'),('tt0116851','Family'),('tt0116851','Drama'),('tt0137204','Comedy'),('tt0137204','Adventure'),('tt0147855','Drama'),('tt0192669','Sci-Fi'),('tt0192669','Action'),('tt0235166','Drama'),('tt0278422','Comedy'),('tt0331314','Comedy'),('tt0331314','Adventure'),('tt0337383','Drama'),('tt0339091','Drama'),('tt0339091','Action'),('tt0339736','Horror'),('tt0347307','Drama'),('tt0352314','Mystery'),('tt0352314','Drama'),('tt0352314','Crime'),('tt0360556','Thriller');

-- Inserting values into director_mapping

INSERT INTO director_mapping
VALUES
('tt0038733','nm0003836'),('tt0038733','nm0696247'),('tt0060908','nm0003606'),('tt0069049','nm0000080'),('tt0082620','nm0716460'),('tt0083907','nm0000600'),('tt0085953','nm0490551'),('tt0100275','nm0749914'),('tt0100275','nm0765384'),('tt0147855','nm0611531'),('tt0192669','nm0939869'),('tt0235166','nm0003761'),('tt0339091','nm0478713'),('tt0339736','nm1274189'),('tt0347307','nm0652673'),('tt0360556','nm1023919'),('tt0427543','nm0853374'),('tt0451279','nm0420941'),('tt0491175','nm0000123'),('tt0491203','nm0149491'),('tt0800325','nm0871860'),('tt0837563','nm1556116'),('tt0837563','nm1552637'),('tt0862930','nm1012100');

-- Inserting values into role_mapping

INSERT INTO role_mapping
VALUES
('tt0038733','nm0000057','actor'),('tt0038733','nm0001375','actress'),('tt0038733','nm0178509','actor'),('tt0038733','nm0126402','actress'),('tt0060908','nm0000869','actor'),('tt0060908','nm0000991','actress'),('tt0060908','nm0105482','actor'),('tt0060908','nm0108400','actor'),('tt0069049','nm0001379','actor'),('tt0069049','nm0462648','actress'),('tt0069049','nm0000953','actor'),('tt0069049','nm0001782','actress'),('tt0082620','nm0003104','actor'),('tt0082620','nm0122782','actress'),('tt0082620','nm0147736','actor'),('tt0082620','nm0588922','actor'),('tt0083907','nm0132257','actor'),('tt0083907','nm0762445','actress'),('tt0083907','nm0217822','actor'),('tt0083907','nm0048260','actress'),('tt0085953','nm0150874','actor'),('tt0085953','nm1845142','actor'),('tt0085953','nm0387360','actor');

-- Inserting values into names

INSERT INTO names
VALUES
('nm0000002','Lauren Bacall','174','1924-09-16',null),('nm0000110','Kenneth Branagh','177','1960-12-10','tt3402236'),('nm0000009','Richard Burton','175','1925-11-10',null),('nm0000114','Steve Buscemi','175','1957-12-13','tt4686844'),('nm0000014','Olivia de Havilland','163','1916-07-01',null),('nm0000130','Jamie Lee Curtis','170','1958-11-22','tt1502407'),('nm0000017','Marlene Dietrich','164','1901-12-27',null);

-- Inserting values into ratings

INSERT INTO ratings
VALUES
('tt0012494',7.7,4695,8),('tt0038733',8.1,17693,8),('tt0060908',7.5,3392,8),('tt0069049',6.9,5014,7),('tt0071145',8.2,789,8),('tt0082620',3.6,236,3),('tt0083907',7.5,174505,8),('tt0085953',6.2,262,6),('tt0095857',7,137,8),('tt0097268',6.9,179,7),('tt0100275',6.6,121,7),('tt0116851',7.6,3149,8),('tt0137204',8.6,264,9),('tt0147855',7.3,171,8),('tt0192669',2.6,449,2),('tt0235166',3.6,145,4),('tt0278422',5,109,8),('tt0331314',5,319,5),('tt0337383',8.2,493,9),('tt0339091',2.4,943,2),('tt0339736',5.5,2577,6);


USE imdb;


/* Now that you have imported the data sets, let’s explore some of the tables.

To begin with, it is beneficial to know the shape of the tables and whether any column has null values.

Further in this segment, you will take a look at 'movies' and 'genre' tables.*/



-- Segment 1:


-- Q1. Find the total number of rows in each table of the schema?

-- Type your code below:



-- Q2. Which columns in the movie table have null values?

-- Type your code below:



-- Now as you can see four columns of the movie table has null values. Let's look at the at the movies released each year.


-- Q3. Find the total number of movies released each year? How does the trend look month wise? (Output expected)


/* Output format for the first part:


+---------------+-------------------+

| Year | number_of_movies|

+-------------------+----------------

| 2017 | 2134 |

| 2018 | . |

| 2019 | . |

+---------------+-------------------+



Output format for the second part of the question:

+---------------+-------------------+

| month_num | number_of_movies|

+---------------+----------------

| 1 | 134 |

| 2 | 231 |

| . | . |

+---------------+-------------------+ */

-- Type your code below:




/*The highest number of movies is produced in the month of March.

So, now that you have understood the month-wise trend of movies, let’s take a look at the other details in the movies table.

We know USA and India produces huge number of movies each year. Lets find the number of movies produced by USA or India for the last year.*/

-- Q4. How many movies were produced in the USA or India in the year 2019??

-- Type your code below:



/* USA and India produced more than a thousand movies(you know the exact number!) in the year 2019.

Exploring table Genre would be fun!!

Let’s find out the different genres in the dataset.*/


-- Q5. Find the unique list of the genres present in the data set?

-- Type your code below:



/* So, RSVP Movies plans to make a movie of one of these genres.

Now, wouldn’t you want to know which genre had the highest number of movies produced in the last year?

Combining both the movie and genres table can give more interesting insights. */


-- Q6.Which genre had the highest number of movies produced overall?

-- Type your code below:



/* So, based on the insight that you just drew, RSVP Movies should focus on the ‘Drama’ genre.

But wait, it is too early to decide. A movie can belong to two or more genres.

So, let’s find out the count of movies that belong to only one genre.*/


-- Q7. How many movies belong to only one genre?

-- Type your code below:



/* There are more than three thousand movies which has only one genre associated with them.

So, this figure appears significant.

Now, let's find out the possible duration of RSVP Movies’ next project.*/


-- Q8.What is the average duration of movies in each genre?

-- (Note: The same movie can belong to multiple genres.)



/* Output format:


+---------------+-------------------+

| genre | avg_duration |

+-------------------+----------------

| thriller | 105 |

| . | . |

| . | . |

+---------------+-------------------+ */

-- Type your code below:




/* Now you know, movies of genre 'Drama' (produced highest in number in 2019) has the average duration of 106.77 mins.

Lets find where the movies of genre 'thriller' on the basis of number of movies.*/


-- Q9.What is the rank of the ‘thriller’ genre of movies among all the genres in terms of number of movies produced?

-- (Hint: Use the Rank function)



/* Output format:

+---------------+-------------------+---------------------+

| genre | movie_count | genre_rank |

+---------------+-------------------+---------------------+

|drama | 2312 | 2 |

+---------------+-------------------+---------------------+*/

-- Type your code below:



/*Thriller movies is in top 3 among all genres in terms of number of movies

In the previous segment, you analysed the movies and genres tables.

In this segment, you will analyse the ratings table as well.

To start with lets get the min and max values of different columns in the table*/





-- Segment 2:


-- Q10. Find the minimum and maximum values in each column of the ratings table except the movie_id column?

/* Output format:

+---------------+-------------------+---------------------+----------------------+-----------------+-----------------+

| min_avg_rating| max_avg_rating | min_total_votes | max_total_votes |min_median_rating|min_median_rating|

+---------------+-------------------+---------------------+----------------------+-----------------+-----------------+

| 0 | 5 | 177 | 2000 | 0 | 8 |

+---------------+-------------------+---------------------+----------------------+-----------------+-----------------+*/

-- Type your code below:



/* So, the minimum and maximum values in each column of the ratings table are in the expected range.

This implies there are no outliers in the table.

Now, let’s find out the top 10 movies based on average rating.*/


-- Q11. Which are the top 10 movies based on average rating?

/* Output format:

+---------------+-------------------+---------------------+

| title | avg_rating | movie_rank |

+---------------+-------------------+---------------------+

| Fan | 9.6 | 5 |

| . | . | . |

| . | . | . |

| . | . | . |

+---------------+-------------------+---------------------+*/

-- Type your code below:

-- It's ok if RANK() or DENSE_RANK() is used too



/* Do you find you favourite movie FAN in the top 10 movies with an average rating of 9.6? If not, please check your code again!!

So, now that you know the top 10 movies, do you think character actors and filler actors can be from these movies?

Summarising the ratings table based on the movie counts by median rating can give an excellent insight.*/


-- Q12. Summarise the ratings table based on the movie counts by median ratings.

/* Output format:


+---------------+-------------------+

| median_rating | movie_count |

+-------------------+----------------

| 1 | 105 |

| . | . |

| . | . |

+---------------+-------------------+ */

-- Type your code below:

-- Order by is good to have



/* Movies with a median rating of 7 is highest in number.

Now, let's find out the production house with which RSVP Movies can partner for its next project.*/


-- Q13. Which production house has produced the most number of hit movies (average rating > 8)??

/* Output format:

+------------------+-------------------+---------------------+

|production_company|movie_count | prod_company_rank|

+------------------+-------------------+---------------------+

| The Archers | 1 | 1 |

+------------------+-------------------+---------------------+*/

-- Type your code below:



-- It's ok if RANK() or DENSE_RANK() is used too

-- Answer can be Dream Warrior Pictures or National Theatre Live or both


-- Q14. How many movies released in each genre during March 2017 in the USA had more than 1,000 votes?

/* Output format:


+---------------+-------------------+

| genre | movie_count |

+-------------------+----------------

| thriller | 105 |

| . | . |

| . | . |

+---------------+-------------------+ */

-- Type your code below:



-- Lets try to analyse with a unique problem statement.

-- Q15. Find movies of each genre that start with the word ‘The’ and which have an average rating > 8?

/* Output format:

+---------------+-------------------+---------------------+

| title | avg_rating | genre |

+---------------+-------------------+---------------------+

| Theeran | 8.3 | Thriller |

| . | . | . |

| . | . | . |

| . | . | . |

+---------------+-------------------+---------------------+*/

-- Type your code below:



-- You should also try your hand at median rating and check whether the ‘median rating’ column gives any significant insights.

-- Q16. Of the movies released between 1 April 2018 and 1 April 2019, how many were given a median rating of 8?

-- Type your code below:



-- Once again, try to solve the problem given below.

-- Q17. Do German movies get more votes than Italian movies?

-- Hint: Here you have to find the total number of votes for both German and Italian movies.

-- Type your code below:



-- Answer is Yes


/* Now that you have analysed the movies, genres and ratings tables, let us now analyse another table, the names table.

Let’s begin by searching for null values in the tables.*/





-- Segment 3:


-- Q18. Which columns in the names table have null values??

/*Hint: You can find null values for individual columns or follow below output format

+---------------+-------------------+---------------------+----------------------+

| name_nulls | height_nulls |date_of_birth_nulls |known_for_movies_nulls|

+---------------+-------------------+---------------------+----------------------+

| 0 | 123 | 1234 | 12345 |

+---------------+-------------------+---------------------+----------------------+*/

-- Type your code below:




/* There are no Null value in the column 'name'.

The director is the most important person in a movie crew.

Let’s find out the top three directors in the top three genres who can be hired by RSVP Movies.*/


-- Q19. Who are the top three directors in the top three genres whose movies have an average rating > 8?

-- (Hint: The top three genres would have the most number of movies with an average rating > 8.)

/* Output format:


+---------------+-------------------+

| director_name | movie_count |

+---------------+-------------------|

|James Mangold | 4 |

| . | . |

| . | . |

+---------------+-------------------+ */

-- Type your code below:



/* James Mangold can be hired as the director for RSVP's next project. Do you remeber his movies, 'Logan' and 'The Wolverine'.

Now, let’s find out the top two actors.*/


-- Q20. Who are the top two actors whose movies have a median rating >= 8?

/* Output format:


+---------------+-------------------+

| actor_name | movie_count |

+-------------------+----------------

|Christain Bale | 10 |

| . | . |

+---------------+-------------------+ */

-- Type your code below:



/* Have you find your favourite actor 'Mohanlal' in the list. If no, please check your code again.

RSVP Movies plans to partner with other global production houses.

Let’s find out the top three production houses in the world.*/


-- Q21. Which are the top three production houses based on the number of votes received by their movies?

/* Output format:

+------------------+--------------------+---------------------+

|production_company|vote_count | prod_comp_rank|

+------------------+--------------------+---------------------+

| The Archers | 830 | 1 |

| . | . | . |

| . | . | . |

+-------------------+-------------------+---------------------+*/

-- Type your code below:



/*Yes Marvel Studios rules the movie world.

So, these are the top three production houses based on the number of votes received by the movies they have produced.


Since RSVP Movies is based out of Mumbai, India also wants to woo its local audience.

RSVP Movies also wants to hire a few Indian actors for its upcoming project to give a regional feel.

Let’s find who these actors could be.*/


-- Q22. Rank actors with movies released in India based on their average ratings. Which actor is at the top of the list?

-- Note: The actor should have acted in at least five Indian movies.

-- (Hint: You should use the weighted average based on votes. If the ratings clash, then the total number of votes should act as the tie breaker.)


/* Output format:

+---------------+-------------------+---------------------+----------------------+-----------------+

| actor_name | total_votes | movie_count | actor_avg_rating |actor_rank |

+---------------+-------------------+---------------------+----------------------+-----------------+

| Yogi Babu | 3455 | 11 | 8.42 | 1 |

| . | . | . | . | . |

| . | . | . | . | . |

| . | . | . | . | . |

+---------------+-------------------+---------------------+----------------------+-----------------+*/

-- Type your code below:



-- Top actor is Vijay Sethupathi


-- Q23.Find out the top five actresses in Hindi movies released in India based on their average ratings?

-- Note: The actresses should have acted in at least three Indian movies.

-- (Hint: You should use the weighted average based on votes. If the ratings clash, then the total number of votes should act as the tie breaker.)

/* Output format:

+---------------+-------------------+---------------------+----------------------+-----------------+

| actress_name | total_votes | movie_count | actress_avg_rating |actress_rank |

+---------------+-------------------+---------------------+----------------------+-----------------+

| Tabu | 3455 | 11 | 8.42 | 1 |

| . | . | . | . | . |

| . | . | . | . | . |

| . | . | . | . | . |

+---------------+-------------------+---------------------+----------------------+-----------------+*/

-- Type your code below:



/* Taapsee Pannu tops with average rating 7.74.

Now let us divide all the thriller movies in the following categories and find out their numbers.*/



/* Q24. Select thriller movies as per avg rating and classify them in the following category:


Rating > 8: Superhit movies

Rating between 7 and 8: Hit movies

Rating between 5 and 7: One-time-watch movies

Rating < 5: Flop movies

--------------------------------------------------------------------------------------------*/

-- Type your code below:



/* Until now, you have analysed various tables of the data set.

Now, you will perform some tasks that will give you a broader understanding of the data in this segment.*/



-- Segment 4:


-- Q25. What is the genre-wise running total and moving average of the average movie duration?

-- (Note: You need to show the output table in the question.)

/* Output format:

+---------------+-------------------+---------------------+----------------------+

| genre | avg_duration |running_total_duration|moving_avg_duration |

+---------------+-------------------+---------------------+----------------------+

| comdy | 145 | 106.2 | 128.42 |

| . | . | . | . |

| . | . | . | . |

| . | . | . | . |

+---------------+-------------------+---------------------+----------------------+*/

-- Type your code below:



-- Round is good to have and not a must have; Same thing applies to sorting

-- Let us find top 5 movies of each year with top 3 genres.


-- Q26. Which are the five highest-grossing movies of each year that belong to the top three genres?

-- (Note: The top 3 genres would have the most number of movies.)


/* Output format:

+---------------+-------------------+---------------------+----------------------+-----------------+

| genre | year | movie_name |worldwide_gross_income|movie_rank |

+---------------+-------------------+---------------------+----------------------+-----------------+

| comedy | 2017 | indian | $103244842 | 1 |

| . | . | . | . | . |

| . | . | . | . | . |

| . | . | . | . | . |

+---------------+-------------------+---------------------+----------------------+-----------------+*/

-- Type your code below:


-- Top 3 Genres based on most number of movies



-- Finally, let’s find out the names of the top two production houses that have produced the highest number of hits among multilingual movies.

-- Q27. Which are the top two production houses that have produced the highest number of hits (median rating >= 8) among multilingual movies?

/* Output format:

+-------------------+-------------------+---------------------+

|production_company |movie_count | prod_comp_rank|

+-------------------+-------------------+---------------------+

| The Archers | 830 | 1 |

| . | . | . |

| . | . | . |

+-------------------+-------------------+---------------------+*/

-- Type your code below:



-- Multilingual is the important piece in the above question. It was created using POSITION(',' IN languages)>0 logic

-- If there is a comma, that means the movie is of more than one language



-- Q28. Who are the top 3 actresses based on number of Super Hit movies (average rating >8) in drama genre?

/* Output format:

+---------------+-------------------+---------------------+----------------------+-----------------+

| actress_name | total_votes | movie_count |actress_avg_rating |actress_rank |

+---------------+-------------------+---------------------+----------------------+-----------------+

| Laura Dern | 1016 | 1 | 9.60 | 1 |

| . | . | . | . | . |

| . | . | . | . | . |

+---------------+-------------------+---------------------+----------------------+-----------------+*/

-- Type your code below:



/* Q29. Get the following details for top 9 directors (based on number of movies)

Director id

Name

Number of movies

Average inter movie duration in days

Average movie ratings

Total votes

Min rating

Max rating

total movie durations


Format:

+---------------+-------------------+---------------------+----------------------+--------------+--------------+------------+------------+----------------+

| director_id | director_name | number_of_movies | avg_inter_movie_days | avg_rating | total_votes | min_rating | max_rating | total_duration |

+---------------+-------------------+---------------------+----------------------+--------------+--------------+------------+------------+----------------+

|nm1777967 | A.L. Vijay | 5 | 177 | 5.65 | 1754 | 3.7 | 6.9 | 613 |

| . | . | . | . | . | . | . | . | . |

| . | . | . | . | . | . | . | . | . |

| . | . | . | . | . | . | . | . | . |

| . | . | . | . | . | . | . | . | . |

| . | . | . | . | . | . | . | . | . |

| . | . | . | . | . | . | . | . | . |

| . | . | . | . | . | . | . | . | . |

| . | . | . | . | . | . | . | . | . |

+---------------+-------------------+---------------------+----------------------+--------------+--------------+------------+------------+----------------+


--------------------------------------------------------------------------------------------*/

-- Type you code below:




To Get solution of above queries or need any other database related help then you can send your requirement details at:


And get complete solution without any plagiarism issue with an affordable price.

bottom of page