You are on page 1of 1

8.

select PID, Name


from Person where PID not in(select distinct(PID)
from M Cast as C1 natural join Movie as M1
where exists(select MID
from M Cast as C2 natural join Movie as M2
where C1.PID = C2.PID and (M2.year - 3) > M1.year
and not exists(select M ID from M Cast as C3 natural join Movie as M3where C1.PID =
C3.PID and M1.year < M3.yearand M3.year < M2.year)));

9. select P1.PID, P1.Name, count(Movie.MID) as movies with yc


from Person as P1 natural join M Cast natural join Movie
join M Director on (Movie.MID = MDirector.MID)
join Person as P2 on (MDirector.PID = P2.PID)
where P2.Name = ‘Yash Chopra’
group by P1.PID
having count(Movie.MID) >all (select count(Movie.MID)
from Person as P3 natural join M Cast natural join Movie
join M Director on (Movie.MID = MDirector.MID)
join Person as P4 on (MDirector.PID = P4.PID)
where P1.PID = P3.PID and P4.Name != ‘Yash Chopra’
group by P4.PID)
order by movies with yc desc;

10. select distinct PID, Name


from Person natural join M Cast
where Name <> ‘Shah Rukh Khan’ and MID in (select MID
from M Cast where PID in (select PID
from Person natural join M Cast
where Name <> ‘Shah Rukh Khan’ and MID in (select MID
from Person natural join M Cast
where Name = ‘Shah Rukh Khan’)))and PID not in (select PID
from Person natural join M Cast
where Name <> ‘Shah Rukh Khan’ and MID in (select MID
from Person natural join M Cast
where Name = ‘Shah Rukh Khan’));

4.select Name, count(MID)from Person natural join MDirectorgroup by PIDhaving


count(MID) >= 10order by count(MID) desc;36 rows in setQ2.11 For each year, count
the number of movies in that year that had onlyfemale actors.ANSselect year,
count(distinct MID)-(select count(distinct MID)from Person natural join MCast
natural join Movie as M2where M1.year = M2.year and gender = ’male’) as
femalemoviecountfrom Movie as M1 natural join MCastgroup by M1.yearorder by year
desc;68 rows in set5

3.select distinct(PID), Namefrom Person natural join MCast natural join Moviewhere
year < 1970 and PID in (select distinct(PID)from Person natural join MCast natural
join Moviewhere year > 1990);

6.select title, count(distinct PID) as castsizefrom Movie natural join MCastgroup


by MIDorder by castsize desc limit 1;

7.select (floor((year - (select min(year) from Movie)) / 10) * 10+ (select


min(year) from Movie)) as startyear,(floor((year - (select min(year) from Movie)) /
10) * 10+ (select min(year) from Movie) + 9) as endyear, count(MID)from Movie
group by startyearorder by count(MID) desc limit 1;

8.

You might also like