набор данных imdb выберите mov ie количество в соответствии с годом с фильмами только с участием женщин - PullRequest
0 голосов
/ 03 августа 2020

enter image description here report for each year the percentage of movies in that year with only female actors, and the total number of movies made that year. For example, one answer will be: 1990 31.81 13522 meaning that in 1990 there were 13,522 movies, and 31.81% had only female actors. You do not need to round your answer.

following code

select a.year, a.c*100.00/b.c as percentage, b.c as total_overall
from (select z.year, count(*) as c
      from movie z
      where not exists (select *
                        from person x,M_cast xy
                        where x.pid = xy.pid and xy.mid = z.mid and x.Gender!='Female')
      group by z.year) a,
     (select z.year, count(*) as c from movie z group by z.year) b
where a.year=b.year
order by a.year;

following code is not working

select z.year, count(*)
from movie z
where not exists (select *
                  from actor x, casts xy
                  where x.id = xy.pid and xy.mid = z.id and x.gender!='F')
group by z.year;

please tell me query for movies with only female how to select following output im getting enter image description here

guide me how to select movie with only female actors

введите описание изображения здесь

как написать sql запрос для вышеуказанных операторов

1 Ответ

0 голосов
/ 03 августа 2020

Вы можете использовать два уровня агрегации:

select movie_year, count(*) no_movies, avg(has_male_actor = 0) ratio
from (
    select m.year movie_year, max(p.gender = 'Male') has_male_actor
    from movie m
    inner join m_cast mc on mc.mid = m.mid
    inner join person p on pid = mc.pid
    group by m.mid, m.year
) t
group by movie_year

Подзапрос выдает одну строку на mov ie с флагом, который указывает, появляется ли какой-либо актер-мужчина в приведении. Затем внешний запрос агрегирует по годам и вычисляет количество и соотношение фильмов, в которых есть только актрисы женского пола (выраженное десятичным числом от 0 до 1).

...