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
- R
- insertion sort
- datastructure
- JSON
- buffer
- coding test
- 이스케이프 문자
- Graph
- s
- Stack
- stream
- Algorithm
- list 컬렉션
- 혼자 공부하는 C언어
- C 언어 코딩 도장
- 알기쉬운 알고리즘
- 윤성우 열혈자료구조
- C programming
- Selection Sorting
- Serialization
- 이것이 자바다
- 윤성우의 열혈 자료구조
- 메모리구조
Archives
- Today
- Total
Engineering Note
184. Department Highest Salary 본문
Problem Solving/LeetCode(SQL)
184. Department Highest Salary
Software Engineer Kim 2021. 7. 24. 19:53문제
https://leetcode.com/problems/department-highest-salary/
코드
# Write your MySQL query statement below
SELECT d.name As Department, e.Name as Employee, Salary
FROM Employee e
left join
Department d
on e.DepartmentId = d.id
where Salary in
(SELECT MAX(Salary) from Employee group by DepartmentId )
실패코드
# Write your MySQL query statement below
SELECT d.name, e.Name, max(salary)
FROM Employee e
left join
Department d
on e.DepartmentId = d.id
group by e.DepartmentId
문제해결방법
- 실패코드를 보면 최대값이 하나만 검색되는 문제가 있다.
- 그래서 where in 을 이용해 goupry by department를 하고 최대값이 포함된 모든 컬럼을 고르는 방법으로 문제를 바꾸어 풀었다.
'Problem Solving > LeetCode(SQL)' 카테고리의 다른 글
601. Human Traffic of Stadium (0) | 2021.05.29 |
---|---|
596. Classes More Than 5 Students (0) | 2021.05.29 |
626. Exchange Seats (0) | 2021.05.29 |
178. Rank Scores (0) | 2021.05.21 |
180. Consecutive Numbers (0) | 2021.05.21 |
Comments