Salesforce Fact #419 | Nth highest using SOQL
Suppose we have a use case where we need to find the Nth highest value of a number field in an Object. We can get the same using SOQL.
In this example, we are getting the 2nd highest value of NumberOfEmployees in Account object. Here is the SOQL:
SELECT NumberOfEmployees FROM Account GROUP BY NumberOfEmployees ORDER BY NumberOfEmployees DESC NULLS LAST LIMIT 1 OFFSET 1. Here OFFSET=N-1.
Comments
Post a Comment