Question: I need help doing this step: Write a single SQL statement that will select the name of each actor and the average box office revenue
I need help doing this step:
-
Write a single SQL statement that will select the name of each actor and the average box office revenue for all of the movies in which that actor has appeared. These results should be sorted by average revenue in descending order (largest to smallest).
Please see code underneath
IF OBJECT_ID('MovieActor') IS NOT NULL DROP TABLE MovieActor;
IF OBJECT_ID('Movie') IS NOT NULL DROP TABLE Movie;
IF OBJECT_ID('Actor') IS NOT NULL DROP TABLE Actor;
CREATE TABLE Movie (
movieId Int NOT NULL,
title VarChar(100) NOT NULL,
yearReleased Int NOT NULL,
totalRevenue Money NOT NULL,
CONSTRAINT moviePK PRIMARY KEY (movieId)
);
INSERT INTO Movie
(movieId, title, yearReleased, totalRevenue)
VALUES (
'101', 'Avatar', '2009', '2787965087');
INSERT INTO Movie
(movieId, title, yearReleased, totalRevenue)
VALUES (
'102', 'Avengers: Infinity War', '2018', '2048359754');
INSERT INTO Movie
(movieId, title, yearReleased, totalRevenue)
VALUES (
'103', 'Jurassic World', '2015', '1671713208');
INSERT INTO Movie
(movieId, title, yearReleased, totalRevenue)
VALUES (
'104', 'Black Panther', '2018', '1346913161');
INSERT INTO Movie
(movieId, title, yearReleased, totalRevenue)
VALUES
('105', 'The Lord of the Rings: The Return of the King', '2009', '1119929521');
CREATE TABLE Actor (
actorId Integer NOT NULL,
name Char(50) NOT NULL,
agentPhone Float(12) NOT NULL,
CONSTRAINT actorPK PRIMARY KEY(actorId)
);
INSERT INTO Actor
(actorId, name, agentPhone)
VALUES (
'1', 'Zoe Saldana', '2655553267');
INSERT INTO Actor
(actorId, name, agentPhone)
VALUES (
'2', 'Chadwick Boseman', '4435552300');
INSERT INTO Actor
(actorId, name, agentPhone)
VALUES (
'3', 'Chris Pratt', '6495553992');
INSERT INTO Actor
(actorId, name, agentPhone)
VALUES (
'4', 'Andy Serkis', '6685557475');
CREATE TABLE MovieActor (
movieId Integer NOT NULL,
actorId Integer NOT NULL,
CONSTRAINT movieactorPK PRIMARY KEY(movieId, actorId),
CONSTRAINT movieFK FOREIGN KEY(movieId) REFERENCES Movie(movieId),
CONSTRAINT actorFK FOREIGN KEY(actorId) REFERENCES Actor(actorId)
);
INSERT INTO MovieActor
(movieId, actorId)
VALUES (
'104', '4');
INSERT INTO MovieActor
(movieId, actorId)
VALUES (
'102', '2');
INSERT INTO MovieActor
(movieId, actorId)
VALUES (
'103', '3');
INSERT INTO MovieActor
(movieId, actorId)
VALUES (
'101', '1');
INSERT INTO MovieActor
(movieId, actorId)
VALUES (
'105', '4');
INSERT INTO MovieActor
(movieId, actorId)
VALUES (
'102', '3');
INSERT INTO MovieActor
(movieId, actorId)
VALUES (
'102', '1');
INSERT INTO MovieActor
(movieId, actorId)
VALUES (
'104', '2');
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
