본문 바로가기

열정가득한 개발자의 이야기/hacker Rank SQL 문제

HackerRank mysql (Placements)

 

 

Hi.

long time no use English explaining the sql query. 

Let's starts!

 

 

https://www.hackerrank.com/challenges/placements/problem?isFullScreen=true

 

Placements | HackerRank

Write a query to output the names of those students whose best friends got offered a higher salary than them.

www.hackerrank.com

 

 

First of all, I will explain this question.

 

Summarize the question : 

even if this question's difficulty is medium, but it is not that hard. 

we just gain the studenst's name who got a less salary than friend.

it is so cruel.. right..?

 

so, there is 3 simple table.

let's see which cloum contained in each table.

there are name, Id, friend_id and etc.. please see the below.

 

 

so, the result must be like this.

it should be ordered by friend salary and should not contain the name who get more salary than friend.

 

For solving this problem, we should use join and compared the amount of salary between friend and student.

 

so, my query is like that.

is it so simple right?

 

I just make the temporary table by using 'with' claues and then use 'join' clause.

and then compared the salary by using 'where' clause.

 

and them, just completed it  right away. hahaha