ろくろ猫のブログ

しがない会社員の備忘log

【SQL練習】SQL Bolt lesson10

lesson10の問題

f:id:rokuroneko:20210731221918j:plain

問題一覧はこちらです。
SQLBolt - Learn SQL - SQL Lesson 10: Queries with aggregates (Pt. 1)
f:id:rokuroneko:20200222232309p:plain

以下が解答となります。

1.解答

Find the longest time that an employee has been at the studio

従業員がスタジオにいた最長時間を見つけてください

f:id:rokuroneko:20200222232325p:plain

SELECT MAX(years_employed) FROM employees;


2.解答

For each role, find the average number of years employed by employees in that role

各役割について、その役割の従業員の平均雇用年数を見つけてください

f:id:rokuroneko:20200222232341p:plain

SELECT role, AVG(years_employed) FROM employees GROUP BY role;

役職ごとに集計して、その平均値を出す

3.解答

Find the total number of employee years worked in each building

各建物で働いた従業員の合計年数を見つけてください

f:id:rokuroneko:20200222232351p:plain

SELECT building, SUM(years_employed) FROM employees GROUP BY building;