This project involves a comprehensive analysis of Netflix's movies and TV shows data using SQL. The goal is to extract valuable insights and answer various business questions based on the dataset. The following README provides a detailed account of the project's objectives, business problems, solutions, findings, and conclusions.
- Analyze the distribution of content types (movies vs TV shows).
- Identify the most common ratings for movies and TV shows.
- List and analyze content based on release years, countries, and durations.
- Explore and categorize content based on specific criteria and keywords.
The data for this project is sourced from the Kaggle dataset:
- Dataset Link: Movies Dataset
DROP TABLE IF EXISTS netflix;
CREATE TABLE netflix
(
show_id VARCHAR(5),
type VARCHAR(10),
title VARCHAR(250),
director VARCHAR(550),
casts VARCHAR(1050),
country VARCHAR(550),
date_added VARCHAR(55),
release_year INT,
rating VARCHAR(15),
duration VARCHAR(15),
listed_in VARCHAR(250),
description VARCHAR(550)
);
SELECT
type ,
COUNT(*)
FROM netflix
GROUP BY 1;
Objective: Determine the distribution of content types on Netflix.
select
type,
rating
from
(
select
type,
rating,
count(*),
rank() over (partition by type order by count(*) desc) as ranking
from netflix
group by 1, 2
) as t1
where
ranking = 1;
Objective: Identify the most frequently occurring rating for each type of content.
select
*
from netflix
where type = 'Movie'
AND
release_year = 2020;
Objective: Retrieve all movies released in a specific year.
select
unnest(string_to_array(country, ',')) as new_country,
count(*) as most_content
from netflix
group by 1
order by 2 desc limit 5;
Objective: Identify the top 5 countries with the highest number of content items.
select
*
from netflix
where type = 'Movie'
AND
duration = (select max(duration) from netflix);
Objective: Find the movie with the longest duration.
select
*
from netflix
where
TO_DATE(date_added, 'Month DD, YYYY') >= CURRENT_DATE - INTERVAL '5 years';
Objective: Retrieve content added to Netflix in the last 5 years.
select
*
from netflix
where
director like '%Rajiv Chilaka%';
Objective: List all content directed by 'Rajiv Chilaka'.
select *
from netflix
where
type ='TV Show'
AND
split_part(duration, ' ',1)::numeric > 5;
Objective: Identify TV shows with more than 5 seasons.
select
unnest(string_to_array(listed_in, ',')) as genre,
count(show_id) as total_content
from netflix
group by 1;
Objective: Count the number of content items in each genre.
return top 5 year with highest avg content release!
select
extract(year from to_date(date_added, 'Month DD, YYYY')) as year,
count(*) as yearly_content,
round(count(*)::numeric/(select count(*) from netflix where country = 'India')::numeric *
100,2) as avg_content_per_year
from netflix
where country = 'India'
group by 1
order by avg_content_per_year desc limit 5;
Objective: Calculate and rank years by the average number of content releases by India.
select *
from netflix
where
type = 'Movie'
AND
listed_in ILIKE '%Documentaries%';
Objective: Retrieve all movies classified as documentaries.
select *
from netflix
where
director is NULL;
Objective: List content that does not have a director.
select *
from netflix
where
casts ILIKE '%Salman Khan%'
AND
release_year > EXTRACT(YEAR from current_date) - 10;
Objective: Count the number of movies featuring 'Salman Khan' in the last 10 years.
select
unnest(string_to_array(casts, ',')) as actors,
count(*) as total_content
from netflix
where
country ILIKE '%India%'
group by 1
order by 2 desc
limit 10;
Objective: Identify the top 10 actors with the most appearances in Indian-produced movies.
with new_table as(
select
*,
case
when
description ILIKE '%kill%' or
description ILIKE '%voilence%' then 'bad_content'
else 'good_content'
end category
from netflix
)
select
category,
count(*) as total_content
from new_table
group by 1
order by 2 desc;
Objective: Categorize content as 'Bad' if it contains 'kill' or 'violence' and 'Good' otherwise. Count the number of items in each category.
- Content Distribution: The dataset contains a diverse range of movies and TV shows with varying ratings and genres.
- Common Ratings: Insights into the most common ratings provide an understanding of the content's target audience.
- Geographical Insights: The top countries and the average content releases by India highlight regional content distribution.
- Content Categorization: Categorizing content based on specific keywords helps in understanding the nature of content available on Netflix.
This analysis provides a comprehensive view of Netflix's content and can help inform content strategy and decision-making.