Part B Pgm9 - DBMS-Lab - Movies Database
Part B Pgm9 - DBMS-Lab - Movies Database
SCHEMA DIAGRAM:
Problem Statement:
Consider the given schema for Movie Database and solve the respective queries.
3. List all actors who acted in a movie before 2000 and also in a movieafter 2015 (use
JOINoperation).
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.
Update rating of all movies directed by ‘Steven Spielberg’ to 5
-- 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)
desc movie_cast;
-- or
SELECT M.Mov_Title
FROM MOVIES M
NATURAL JOIN DIRECTOR D
WHERE D.Dir_Name = 'Hitchcock';
-- 2)Find the movie names where one or more actors acted in two or more movies.
select m.mov_title
from movies m
natural join movie_cast mc
where act_id in (select act_id
from movie_cast
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 2020 (use
JOIN
-- operation).
select distinct act_name
from (actor join movie_cast using(act_id)) join movies using(mov_id)
where 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
select mov_title , max(rev_stars)
from movies natural join rating
group by mov_title
order by mov_title;
/* test
create database test_movie;
use test_movie;
#1
select m.mov_title
from movies m natural join director
where dir_name = 'hitch';
#2
select m.mov_title
from movies m
natural join movie_cast mc
where act_id in (select act_id
from movie_cast
group by act_id
having count(act_id)>1)
group by m.mov_title
having count(*)>1;
#3
select distinct mc.act_id
from movies m
join movie_cast mc on mc.mov_id = m.mov_id
where m.mov_year not between 2000 and 2020;
#4
select m.mov_title, max(rev_stars)
from rating natural join movies m
group by mov_title
order by mov_title;
#5
select * from rating;
update rating
set rev_stars = 5
where mov_id in (select mov_id
from movies natural join director
where dir_name = 'steven');
*/