1

I need to calculate second highest or 4th highest salary etc.. what is the way to calculate it. select salary__c from Staff_Details__c order by salary__c desc

I am getting the salary in desc order but then how to get second.

2

You can get a specific record with LIMIT X OFFSET Y. To get the second-highest Salary, for example:

select salary__c from Staff_Details__c order by salary__c desc nulls last limit 1 offset 1

Note that offset is 0-based, so the second-highest is 1, while fourth-highest would be 3. There's also a limit of OFFSET 2000, so you'll need to come up with alternative methods if that's what you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.