-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetflix_queries.sql
More file actions
68 lines (59 loc) · 1.48 KB
/
netflix_queries.sql
File metadata and controls
68 lines (59 loc) · 1.48 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
-- 1. Count total Movies vs TV Shows
SELECT type, COUNT(*) AS total
FROM netflix
GROUP BY type;
-- 2. Top 10 countries with the most Netflix titles
SELECT country, COUNT(*) AS total_titles
FROM netflix
WHERE country != 'Unknown'
GROUP BY country
ORDER BY total_titles DESC
LIMIT 10;
-- 3. Distribution of content by rating
SELECT rating, COUNT(*) AS count
FROM netflix
GROUP BY rating
ORDER BY count DESC;
-- 4. New titles added each year (trend over time)
SELECT added_year, COUNT(*) AS titles_added
FROM netflix
GROUP BY added_year
ORDER BY added_year;
-- 5. Top 10 directors with the most content
SELECT director, COUNT(*) AS total_content
FROM netflix
WHERE director != 'Unknown'
GROUP BY director
ORDER BY total_content DESC
LIMIT 10;
-- 6. Most common genres (listed_in)
SELECT genre, COUNT(*) AS total
FROM (
SELECT TRIM(value) AS genre
FROM netflix,
json_each('["' || REPLACE(listed_in, ', ', '","') || '"]')
)
GROUP BY genre
ORDER BY total DESC
LIMIT 10;
-- 7. Average duration of movies (in minutes)
SELECT ROUND(AVG(duration_min), 2) AS avg_movie_duration
FROM netflix
WHERE type = 'Movie';
-- 8. TV Shows with the most seasons
SELECT title, num_seasons
FROM netflix
WHERE type = 'TV Show'
ORDER BY num_seasons DESC
LIMIT 10;
-- 9. Oldest released movie still on Netflix
SELECT title, release_year
FROM netflix
WHERE type = 'Movie'
ORDER BY release_year ASC
LIMIT 1;
-- 10. Most recent content added
SELECT title, type, date_added
FROM netflix
ORDER BY date_added DESC
LIMIT 10;