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 |
Tags
- 그룹바이
- SQL 날짜 데이터
- Statistics
- 자연어 논문 리뷰
- 코딩테스트
- SQL코테
- HackerRank
- Window Function
- 설명의무
- 서브쿼리
- CASE
- 자연어 논문
- 카이제곱분포
- inner join
- LSTM
- sql
- 논문리뷰
- torch
- NLP
- t분포
- nlp논문
- MySQL
- leetcode
- sigmoid
- GRU
- update
- 자연어처리
- 짝수
- 표준편차
- airflow
Archives
- Today
- Total
HAZEL
[SQL : LEFT JOIN ] HackerRank : Placements 본문
Placements
>> 문제
You are given three tables: Students, Friends and Packages. Students contains two columns: ID and Name. Friends contains two columns: ID and Friend_ID (ID of the ONLY best friend). Packages contains two columns: ID and Salary (offered salary in $ thousands per month).
Write a query to output the names of those students whose best friends got offered a higher salary than them. Names must be ordered by the salary amount offered to the best friends. It is guaranteed that no two students got same salary offer.
Sample Input
Sample Output
Samantha
Julia
Scarlet
Explanation
See the following table:
Now,
- Samantha's best friend got offered a higher salary than her at 11.55
- Julia's best friend got offered a higher salary than her at 12.12
- Scarlet's best friend got offered a higher salary than her at 15.2
- Ashley's best friend did NOT get offered a higher salary than her
The name output, when ordered by the salary offered to their friends, will be:
- Samantha
- Julia
- Scarlet
>> 푼 코드
SELECT S.NAME
FROM STUDENTS S
LEFT JOIN PACKAGES P ON S.ID = P.ID
LEFT JOIN FRIENDS F ON S.ID = F.ID
LEFT JOIN PACKAGES FP ON F.Friend_id = FP.ID
WHERE P.salary < FP.salary
ORDER BY FP.salary
'DATA ANALYSIS > SQL' 카테고리의 다른 글
[SQL : CASE문 / UPDATE ] LeetCode : 627. Swap Salary (0) | 2021.03.08 |
---|---|
[SQL : HackerRank] Binary Tree Nodes (0) | 2021.03.03 |
[SQL : HackerRank] Weather Observation Station 3 / Weather Observation Station 19 (0) | 2021.03.01 |
[SQL : HackerRank] Top Competitors (0) | 2021.02.28 |
[SQL : HackerRank] Population Density Difference , Weather Observation Station 11, Weather Observation Station 13 (0) | 2021.02.27 |