-
Notifications
You must be signed in to change notification settings - Fork 0
/
movies db script 2.sql
134 lines (119 loc) · 4.81 KB
/
movies db script 2.sql
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
-- SELECT * FROM MovFinLang;
-- 1. Top Performing Movies
-- a. Movies with the highest IMDb ratings.
SELECT TOP (5)
movie_title "Movie",
MAX (imdb_rating) "Ratings"
FROM MovFinLang
GROUP BY movie_title
ORDER BY [Ratings] DESC;
-- b. Movies with the highest revenue.
SELECT TOP (1)
movie_title "Movies",
CAST (MAX (revenue_INR_millions) AS DECIMAL (10, 2)) "Revenue (INR Mln)",
CAST (MAX (revenue_USD_millions) AS DECIMAL (10, 2)) "Revenue (USD Mln)"
FROM MovFinLang
GROUP BY movie_title
ORDER BY [Revenue (INR Mln)] DESC;
-- c. Movies with the highest ROI (Return on Investment).
SELECT TOP (1)
movie_title "Movie",
CAST((revenue_USD_millions - budget_USD_millions) / budget_USD_millions * 100 AS DECIMAL(10,2)) "Percent ROI"
FROM MovFinLang
ORDER BY [Percent ROI] DESC;
-- 2. Industry Analysis
-- a. Comparison of industries (e.g., Bollywood, Hollywood) in terms of total revenue and average IMDb ratings.
SELECT
industry AS "Industry",
CAST (SUM(revenue_INR_millions) AS DECIMAL (10, 2)) "Total Revenue (INR)",
CAST (AVG(imdb_rating) AS DECIMAL (10, 2)) "Average Rating"
FROM MovFinLang
GROUP BY industry;
-- b. Industries producing the highest number of movies.
SELECT
industry "Industry",
COUNT (movie_title) "No. of Movies"
FROM MovFinLang
GROUP BY industry;
-- c. Industry-specific trends in budget and ROI.
SELECT
industry "Industry",
release_year "Release Year",
CAST (AVG(budget_USD_millions) AS DECIMAL (10, 2)) "Avg Budget ($ Mln)",
CAST (AVG((revenue_USD_millions - budget_USD_millions) / budget_USD_millions * 100) AS DECIMAL (10, 2)) "Avg ROI ($ Mln)",
COUNT(*) "No. of Movies"
FROM MovFinLang
GROUP BY industry, release_year;
-- 3. Language-Based Analysis
-- a. Popular languages based on the number of movies made.
SELECT
DISTINCT (language_list) "Languages",
COUNT (movie_title) "No. of Movies"
FROM MovFinLang
GROUP BY language_list
ORDER BY [No. of Movies] DESC;
-- b. Average IMDb rating for movies in each language.
SELECT
DISTINCT (language_list) "Languages",
CAST (AVG(imdb_rating) AS DECIMAL (10, 2)) "Average Rating"
FROM MovFinLang
GROUP BY language_list
ORDER BY [Average Rating] DESC;
-- c. Revenue and budget comparison of movies across languages.
SELECT
DISTINCT (language_list) "Languages",
CAST (AVG(budget_USD_millions) AS DECIMAL (10, 2)) "Avg Budget ($ Mln)",
CAST (AVG(revenue_USD_millions) AS DECIMAL (10, 2)) "Avg Revenue ($ Mln)"
FROM MovFinLang
GROUP BY language_list;
-- 4. Studio Performance
-- a.Top studios producing the highest-grossing movies.
SELECT TOP (5)
studio "Studio",
CAST (SUM(revenue_USD_billions) AS DECIMAL (10, 2)) "Revenue ($ Bln)"
FROM MovFinLang
GROUP BY studio
ORDER BY [Revenue ($ Bln)] DESC;
-- b. Studios with the highest average IMDb ratings.
SELECT TOP (5)
studio "Studio",
CAST (AVG(imdb_rating) AS DECIMAL (10, 2)) "Ratings"
FROM MovFinLang
GROUP BY studio
ORDER BY [Ratings] DESC;
-- 5. Financial Analysis
-- a. Average and median budgets and revenues across all movies.
-- b. Conversion of budgets and revenues into INR and USD for global analysis.
SELECT
movie_title AS "Movies",
CAST(budget_INR_millions AS DECIMAL(10,2)) AS "Budget INR (Mln)",
CAST(revenue_INR_millions AS DECIMAL(10,2)) AS "Revenue INR (Mln)",
CAST(budget_INR_billions AS DECIMAL(10,2)) AS "Budget INR (Bln)",
CAST(revenue_INR_billions AS DECIMAL(10,2)) AS "Revenue INR (Bln)",
CAST(budget_USD_millions AS DECIMAL(10,2)) AS "Budget USD (Mln)",
CAST(revenue_USD_millions AS DECIMAL(10,2)) AS "Revenue USD (Mln)",
CAST(budget_USD_billions AS DECIMAL(10,2)) AS "Budget USD (Bln)",
CAST(revenue_USD_billions AS DECIMAL(10,2)) AS "Revenue USD (Bln)"
FROM
MovFinLang
ORDER BY
"Budget INR (Mln)" DESC, "Revenue INR (Mln)" DESC, "Budget INR (Bln)" DESC, "Revenue INR (Bln)" DESC,
"Budget USD (Mln)" DESC, "Revenue USD (Mln)" DESC, "Budget USD (Bln)" DESC, "Revenue USD (Bln)" DESC;
-- c. Correlation between budget and revenue or budget and IMDb ratings.
-- 6. Time-Based Analysis
-- a. Trend of budgets, revenues, and IMDb ratings over the years.
SELECT
release_year "Years",
CAST(SUM(budget_INR_millions) AS DECIMAL(10,2)) "Total Budget INR (Mln)",
CAST(SUM(revenue_INR_millions) AS DECIMAL(10,2)) "Total Revenue INR (Mln)",
CAST(AVG(imdb_rating) AS DECIMAL(10,2)) AS "Average Rating"
FROM MovFinLang
GROUP BY release_year;
-- ORDER BY [Total Budget INR (Mln)], [Total Revenue INR (Mln)], [Average Rating]; --optional
-- b. Identification of the best year for the movie industry based on total revenue.
SELECT
release_year "Years",
CAST(SUM(revenue_INR_millions) AS DECIMAL(10,2)) "Total Revenue INR (Mln)"
FROM MovFinLang
GROUP BY release_year
ORDER BY [Total Revenue INR (Mln)] DESC;