【SQL練習】SQL Bolt lesson8
lesson8の問題
問題一覧はこちらです。
SQLBolt - Learn SQL - SQL Lesson 8: A short note on NULLs
以下が解答となります。
1.解答
Find the name and role of all employees who have not been assigned to a building
建物に割り当てられていないすべての従業員の名前と役割を見つけてください
SELECT * FROM employees WHERE building IS NULL;
2.解答
Find the names of the buildings that hold no employees
従業員がいない建物の名前を見つけてください
SELECT * FROM buildings WHERE building_name NOT IN (SELECT DISTINCT building FROM employees WHERE building IS NOT NULL);
①:employeesテーブルからbuildingに値が存在しているものを取得する
②:①の結果からbuildingsテーブルのbuilding_nameと一致しないものを取得する