Repository navigation
Expand file tree
/
Copy pathNetflix.sql
More file actions
152 lines (113 loc) · 4.21 KB
/
Copy pathNetflix.sql
File metadata and controls
152 lines (113 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
SELECT *
FROM portfolio.dbo.netflix_tittles
-- I want to standardize my date format
SELECT date_added,
CONVERT(DATE, date_added) AS new_date
FROM portfolio.dbo.netflix_tittles
UPDATE portfolio.dbo.netflix_tittles
SET new_date = CONVERT(DATE, date_added)
ALTER TABLE portfolio.dbo.netflix_tittles
ADD new_date date
-- Changing the Months From Numbers to Text
SELECT
new_date,
DATENAME(month, new_date)
FROM portfolio.dbo.netflix_tittles
ORDER BY new_date DESC
ALTER TABLE portfolio.dbo.netflix_tittles
ADD month_of_date NVARCHAR(255)
UPDATE portfolio.dbo.netflix_tittles
SET month_of_date = DATENAME(month, new_date)
-- I want to clean the country table by breaking it out and adding everything into one column
SELECT country,
PARSENAME(REPLACE(country, ',', '.'), 5),
PARSENAME(REPLACE(country, ',', '.'), 4),
PARSENAME(REPLACE(country, ',', '.'), 3),
PARSENAME(REPLACE(country, ',', '.'), 2),
PARSENAME(REPLACE(country, ',', '.'), 1)
FROM portfolio.dbo.netflix_tittles
ORDER BY country DESC
ALTER TABLE portfolio.dbo.netflix_tittles
ADD new_country NVARCHAR(255)
UPDATE portfolio.dbo.netflix_tittles
SET new_country = PARSENAME(REPLACE(country, ',', '.'), 5)
UPDATE portfolio.dbo.netflix_tittles
SET new_country = PARSENAME(REPLACE(country, ',', '.'), 4)
UPDATE portfolio.dbo.netflix_tittles
SET new_country = PARSENAME(REPLACE(country, ',', '.'), 3)
UPDATE portfolio.dbo.netflix_tittles
SET new_country = PARSENAME(REPLACE(country, ',', '.'), 2)
UPDATE portfolio.dbo.netflix_tittles
SET new_country = PARSENAME(REPLACE(country, ',', '.'), 1)
--i want to clean the new country column by removing the white spaces
UPDATE portfolio.dbo.netflix_tittles
SET new_country = TRIM(new_country)
-- I want to clean the duration table by replacing the nulls with the ones in rating
SELECT rating, duration, ISNULL(duration, rating)
FROM portfolio.dbo.netflix_tittles
WHERE duration is NULL
UPDATE portfolio.dbo.netflix_tittles
SET duration = ISNULL(duration, rating)
FROM portfolio.dbo.netflix_tittles
WHERE duration is NULL
-- I want to check for the diector with the highest Realease
SELECT Top 10 director,
CASE WHEN director = 'Raúl Campos, Jan Suter' THEN 'Raul Campos, Jan Suter'
ELSE director
END AS TOP_10_director,
COUNT(director) AS HighestRelease
FROM portfolio.dbo.netflix_tittles
GROUP BY director
ORDER BY COUNT(director) DESC
--I want to determine whether Netflix has been more focused on TV shows or movies
WITH CTE AS(
SELECT DISTINCT(type), COUNT(type) AS amt
FROM portfolio.dbo.netflix_tittles
GROUP BY type
)
SELECT type,
ROUND(((amt)/(SELECT SUM(amt) FROM CTE)),2) * 100 AS Percentage_type
FROM CTE
GROUP BY type, amt
ORDER BY amt DESC
--Determination on the type of Film Released on Netflix
SELECT DISTINCT(type), COUNT(type) AS amt
FROM portfolio.dbo.netflix_tittles
GROUP BY type
ORDER BY amt DESC
-- The month director releases the most
SELECT
month_of_date,
COUNT(month_of_date) AS TotalReleaseInAMonth
FROM portfolio.dbo.netflix_tittles
WHERE month_of_date is NOT NULL
GROUP BY month_of_date
ORDER BY TotalReleaseInAMonth DESC
-- Top 10 countries that produce the most movies
SELECT TOP 10 new_country, COUNT(new_country) AS PopularCountry
FROM portfolio.dbo.netflix_tittles
GROUP BY new_country
ORDER BY PopularCountry DESC
-- The year with more tvshow and movie release in the last 10 years
WITH Highestyear AS(
SELECT DISTINCT(type), release_year,
COUNT(release_year) OVER (PARTITION BY type ORDER BY release_year DESC) AS TotalRelease
FROM portfolio.dbo.netflix_tittles
)
SELECT TOP 20 *
FROM Highestyear
ORDER BY release_year DESC, TotalRelease DESC
-- The Most rating released by Netflix in the last 10 years for movie
WITH Releasedtype AS (
SELECT type, release_year, rating,
COUNT(rating) OVER (PARTITION BY release_year ORDER BY rating) AS PopularRating
FROM portfolio.dbo.netflix_tittles
)
SELECT DISTINCT(release_year), type, rating, PopularRating
FROM Releasedtype
ORDER BY release_year DESC
--Removing Columns That are not useful
SELECT *
FROM portfolio.dbo.netflix_tittles
ALTER TABLE portfolio.dbo.netflix_tittles
DROP COLUMN date_added, month_of_newdate