Try   HackMD

1965. Employees With Missing Information

(資訊來自於leetcode 1965 Employees With Missing Information)

信息缺失的員工


Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

編寫一個 SQL 查詢來報告所有缺少信息的員工的 ID 。如果出現以下情況,則缺少員工信息:

  • 員工姓名缺失,或
  • 員工的工資不見了。
    返回employee_id 按升序排序的結果表。
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

解題方式:

select employee_id from Employees where employee_id not in (select employee_id from Salaries ) union all select employee_id from Salaries where employee_id not in (select employee_id from Employees ) order by employee_id

解題解析:

我們可以用NOT IN的語法來作使用,先找出不在第一個Table裡面的ID,接著找出不再第二個Table裡面的ID,再用UNION把資料合併起來,最後題目要按升序排序所以在最後要加上order by來幫助排序。
(資訊來自於 (NOT) IN 運算子)