Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- HACKER_RANK
- LeetCode
- Hackerrank
- 직장인자기계발
- meidum
- 파이썬을활용한시계열데이터분석AtoZ올인원패키지Online
- join
- lv.4
- 어려웠음
- 직장인인강
- SQL
- 프리미엄
- 패캠챌린지
- 패스트캠퍼스후기
- 프로그래머스
- 패스트캠퍼스
- easy
- recursive
- 해커랭크
- RANK
- group by
- medium
- solvesql
- row_number
- SELF-JOIN
- MySQL
- 파이썬을활용한시계열데이터분석
- 시계열데이터분석
- 다시풀어보기
- Hard
Archives
- Today
- Total
~고군분투 인생살이~
[1965_EASY] Employees With Missing Information 본문
Employees With Missing Information - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
Table: Employees
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| employee_id | int |
| name | varchar |
+-------------+---------+
employee_id is the primary key for this table.
Each row of this table indicates the name of the employee whose ID is employee_id.
Table: Salaries
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| employee_id | int |
| salary | int |
+-------------+---------+
employee_id is the primary key for this table.
Each row of this table indicates the salary of the employee whose ID is employee_id.
Write an SQL query to report the IDs of all the employees with missing information. The information of an employee is missing if:
- The employee's name is missing, or
- The employee's salary is missing.
Return the result table ordered by employee_id in ascending order.
The query result format is in the following example.
Example 1:
Input:
Employees table:
+-------------+----------+
| employee_id | name |
+-------------+----------+
| 2 | Crew |
| 4 | Haven |
| 5 | Kristian |
+-------------+----------+
Salaries table:
+-------------+--------+
| employee_id | salary |
+-------------+--------+
| 5 | 76071 |
| 1 | 22517 |
| 4 | 63539 |
+-------------+--------+
Output:
+-------------+
| employee_id |
+-------------+
| 1 |
| 2 |
+-------------+
Explanation:
Employees 1, 2, 4, and 5 are working at this company.
The name of employee 1 is missing.
The salary of employee 2 is missing.
문제 조건
- 직원의 이름 누락 혹은 급여가 누락된 직원의 ID를 출력하시오
- employee_id를 기준으로 오름차순 하시오
문제 풀이
- name이 누락된 테이블, salary가 누락 된 테이블을 생성
- left join을 이용해서 employees와 salary 테이블을 연결시키고 각 null값이 있는 employee_id를 출력
- 그 다음 누락된 정보가 담긴 두 테이블을 union으로 합쳐줌
select e.employee_id
from employees e
left join salaries s on e.employee_id = s.employee_id
where s.salary is null
union
select s.employee_id
from salaries s
left join employees e on s.employee_id = e.employee_id
where e.name is null
order by 1
'SQL > LEETCODE' 카테고리의 다른 글
[1355#_MEDIUM]. Activity Participants (0) | 2022.08.08 |
---|---|
[1978#_EASY] Employees Whose Manager Left the Company (0) | 2022.08.07 |
[1939#_EASY] Users That Actively Request Confirmation Messages (0) | 2022.08.07 |
[1341#_MEDIUM] Movie Rating (0) | 2022.08.05 |
[1321#_MEDIUM] Restaurant Growth (0) | 2022.08.05 |
Comments