I'm a novice. I have the following Employee table.
ID Name Country Salary ManagerID
I retrieved the 3rd max salary using the following.
select name , salary From (
select name, salary from
employee sort by salary desc limit 3)
result sort by salary limit 1;
How to do the same to display 3rd max salary for each country? can we use OVER (PARTITION BY country
)? I tried looking in the languageManual Windowing and Analytics but I'm finding it difficult to understand. Please help!
You're definitely on the right track with windowing functions.
row_number()
is a good function to use here.when you order by salary, make sure that it is a numerical type, or it will not be sorted correctly.