Database3 MovieDatabase
Database3 MovieDatabase
Movie Database
Consider the schema for Movie Database:
ACTOR(Act_id, Act_Name, Act_Gender)
DIRECTOR(Dir_id, Dir_Name, Dir_Phone)
MOVIES(Mov_id, Mov_Title, Mov_Year, Mov_Lang, Dir_id)
MOVIE_CAST(Act_id, Mov_id, Role)
RATING(Mov_id, Rev_Stars)
ER Diagram for Movie Database
Schema Diagram
Table Creation
create table actor create table director
( (
act_id int, dir_id int,
act_name varchar(10), dir_name varchar(20),
act_gender char(1), dir_phone bigint,
primary key(act_id) primary key(dir_id)
); );
create table movies
(
mov_id int,
mov_title varchar(10),
mov_year int,
mov_lang varchar(10),
dir_id int,
primary key(mov_id),
foreign key(dir_id) references director(dir_id)
);
create table moviecast
(
act_id int,
mov_id int,
role varchar(10),
primary key(act_id,mov_id),
foreign key(act_id) references actor(act_id),
foreign key(mov_id) references movies(mov_id)
);
select mov_title
from movies m, director d
where m.dir_id = d.dir_id and d.dir_name ='Hitchcock';
2. Find the movie names where one or more actors acted in two
or more movies.
2. Find the movie names where one or more actors acted in two
or more movies.
SELECT ACT_ID, MOV_TITLE
FROM MOVIES M, MOVIECAST MV
WHERE M.MOV_ID=MV.MOV_ID AND
ACT_ID IN ( SELECT ACT_ID
FROM MOVIECAST
GROUP BY ACT_ID
HAVING COUNT(ACT_ID)>=1 )
GROUP BY MOV_TITLE
HAVING COUNT(*)>1;
3. List all actors who acted in a movie before 2000 and also in a movie after
2015 (use JOIN operation).
3. List all actors who acted in a movie before 2000 and also in a movie after
2015 (use JOIN operation).
SELECT ACT_NAME, MOV_TITLE, MOV_YEAR
FROM ACTOR A JOIN MOVIECAST C ON A.ACT_ID=C.ACT_ID
JOIN MOVIES M ON C.MOV_ID=M.MOV_ID
WHERE M.MOV_YEAR NOT BETWEEN 2000 AND 2015;
4. Find the title of movies and number of stars for each movie that has at least
one rating and find the highest number of stars that movie received. Sort the
result by movie title.
4. Find the title of movies and number of stars for each movie that has at
least one rating and find the highest number of stars that movie received.
Sort the result by movie title.
select mov_title,max(rev_stars)
from movies m, rating r
where m.mov_id = r.mov_id
group by (m.mov_id)
having max(rev_stars)>=1
order by m.mov_title;
5. Update rating of all movies directed by ‘Steven Spielberg’ to 5.
5. Update rating of all movies directed by ‘Steven Spielberg’ to 5.
d.dir_name=‘Steven Spielberg’);