문제

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.

*

 

 

실행 코드

 

3개의 테이블이 제시되어 있는데, 먼저 본인을 기준으로 연봉 테이블을 구해준 뒤, 본인의 친구 기준으로 연봉 테이블을 연결해주어야 한다.

나는 from절에서 서브쿼리를 사용해서 조건을 추가했다.

 

1. 서브쿼리를 통해 본인의 연봉 제시

2. 본 쿼리에서 'INNER JOIN Packages P ON P.ID = A.Friend_ID' 구문을 추가하여 친구의 연봉 구분한 후 WHERE절로 비교

 

 

+ Recent posts