【SQL練習】SQL Bolt lesson11
lesson11の問題
問題一覧はこちらです。
SQLBolt - Learn SQL - SQL Lesson 11: Queries with aggregates (Pt. 2)
以下が解答となります。
1.解答
Find the number of Artists in the studio (without a HAVING clause)
スタジオ内のアーティストの数を見つけてください(HAVING句なし)
SELECT count(*) FROM employees WHERE role = 'Artist';
①:役割を条件に検索する
②:①の検索結果のレコード数を取得する
2.解答
Find the number of Employees of each role in the studio
スタジオの各役割の従業員数を見つけてください
SELECT role, count(*) FROM employees GROUP BY role;
3.解答
Find the total number of years employed by all Engineers
すべてのエンジニアが雇用合計年数を調べてください
SELECT building, SUM(years_employed) FROM employees GROUP BY building;
①:役割で集計する
②:①の集計結果から抽出条件を指定する
③:②の取得結果を合算する