DB - 영화 정보 데이터 실습 - 3

박근수·2024년 1월 29일

DB

목록 보기
9/10

문제

Q21. 한국인 이면서 '원'씨 성을 가진 배우 조회

select * from actor where name like '원%' and country in ('한국');

Q22. 대전시에 있는 상영관 중에서 좌석수가 500~1000 사이인 극장이름 조회

select screen_name, seat_count from screen
where sido = '대전시' and seat_count between 500 and 1000;

Q23. 시도별 상영관의 전체 좌석 수, 최대 좌석 수, 최소 좌석 수, 평균 좌석 수 내용을 조회

select sido
    , sum(seat_count) as seat_count_sum
    , max(seat_count) as seat_count_max
    , min(seat_count) as seat_count_min
    , ceil(avg(seat_count)) as seat_count_avg
from screen where seat_count > 0
group by sido;

Q24. 시도별 평균 좌석수가 900 이상인 상영관 조회

select sido
    ,  round(avg(seat_count), 2) as seat_count_avg
from screen group by sido
having seat_count_avg >= 900;

Q25. 영화인 중에서 3월에 태어난 사람 중 직업이 감독인 사람의 한글, 영문 이름 조회

select name, eng_name
    , case
        when country = '한국' then '국내'
        else '국외'
      end as country_comment
from actor where domain in ('감독')
    and length(trim(birth)) = 10
    and str_to_date(birth, '%Y-%m-%d') is not null
    and month(str_to_date(birth, '%Y-%m-%d')) = 3;

Q26. 제주도에 위치한 상영관을 좌석수가 많은 순으로 정렬

select * from screen
where sido = '제주도'
order by seat_count desc;

Q27. 한국에서 개최되는 주요 축제가 개최된 도시의 상영권 수를 각각 조회

select f2.*
    , ifnull(s.screen_count_sum, 0) as screen_count_sum
from
(
    select concat(city, '시') as city from festival
         where country = '한국'
         and important_flag = '예'
) f2
    left join
    (
       select sido
    , sum(screen_count) as screen_count_sum
        from screen group by sido
    ) s on s.sido = f2.city;

Q28. 새로운 축제를 등록하기 위해서 code 값의 최대값에 +1을 더한 코드값 조회

select ifnull(max(code), 0) + 1 as plus_code from festival;

Q29. 한국 배우 중 이름과 영문이름이 존재하고, 생년월일 데이터가 정확한 배우의 전체 개수와 이름 순으로 10개 단위로 페이징 처리

select row_number() over (order by a.name) as ranking,
    a.* from actor a
         where a.country = '한국'
         and a.domain = '배우'
         and length(trim(a.birth)) = 10
         and str_to_date(a.birth, '%Y-%m-%d') is not null
         and a.name is not null and trim(a.name) <> ''
         and a.eng_name is not null and trim(a.name) <> ''
order by a.name limit 0, 10;

Q30. 영화인이 속한 국가와 축제가 진행되는 국가 모두 조회

select distinct country
from actor where country is not null and trim(country) <> ''
union
select distinct country
from festival where country is not null and trim(country) <> ''

profile
개발블로그

0개의 댓글