简体   繁体   中英

Second Highest Salary using JPA method

I recently faced an interview question to find 2nd highest salary from MySQL table.

I gave the query,

select Distinct salary from Employee order by salary desc limit 1 offset 2.

But he asked me to write the same with JPA in build method queries..

I was able to guess like findBySalaryGreaterThan..

Not able to get the correct answer..

How to write JPA in build method query for second highest salary..

Have you got this basic query in JPA?

So just add pagination to that query, set the page size to 1 and get the second page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM