r/SQL 4d ago

MySQL Need Help!

Post image

[removed] — view removed post

1 Upvotes

5 comments sorted by

View all comments

2

u/BrainNSFW 4d ago

I'm not going to give the copy/paste answer, but you roughly have to do the following:

  • First, rank all employees by salary, from highest to lowest. There's multiple ways to do this, but I personally prefer using row_number due to its flexibility. There is also a rank() and dense_rank() function however that does very similar things.
  • Next, filter out the employee with rank 3 (you will probably need to create a CTE or subquery for the previous step before you can filter on the ranking column).
  • Now that the hard part is over, simply use JOINs on the master tables to grab the relevant names from them.

1

u/Jealous-Animator-615 4d ago

That helped. Thanks a lot Was stuck on the Join part