【SQL練習】SQL Bolt lesson12
lesson12の問題
問題一覧はこちらです。
SQLBolt - Learn SQL - SQL Lesson 12: Order of execution of a Query
以下が解答となります。
1.解答
Find the number of movies each director has directed
各監督が監督した映画の数を見つけてください
SELECT director, count(*) FROM movies GROUP BY director;
2.解答
Find the total domestic and international sales that can be attributed to each director
監督別に国内および海外の総売上高を見つけてください
SELECT director, SUM(domestic_sales + international_sales) FROM movies INNER JOIN boxoffice ON movies.id = boxoffice.movie_id GROUP BY director;
①:IDでmoviesテーブルとboxofficeテーブルを紐づける
②:①の結果から監督で集計する
③:②の結果から国内および海外の総売上高を抽出する
SELECT編はここまでとなります。