PMS Information Systems
Welcome to PMS Information Systems - IBM i (AS/400) Forum !!!

Get Answers for all your queries on IBM i (AS/400).

Join the forum, it's quick and easy

PMS Information Systems
Welcome to PMS Information Systems - IBM i (AS/400) Forum !!!

Get Answers for all your queries on IBM i (AS/400).
PMS Information Systems
Would you like to react to this message? Create an account in a few clicks or log in to continue.

SQL TIP: To find out the N th highest and N th lowest values from table.

Go down

SQL TIP: To find out the N th highest and N th lowest values from table. Empty SQL TIP: To find out the N th highest and N th lowest values from table.

Post  maran Sat Oct 15, 2016 12:50 am

For example to find out the 2nd highest and 2nd lowest salary from EMPMST table.

2nd Highest salary
SELECT * FROM EMPMST A WHERE 2 = (SELECT COUNT(*) FROM EMPMST B WHERE A.EMPSAL <= B.EMPSAL)

2nd Lowest salary
SELECT * FROM EMPMST A WHERE 2 = (SELECT COUNT(*) FROM EMPMST B WHERE A.EMPSAL >= B.EMPSAL)
maran
maran
Admin

Posts : 442
Join date : 2009-07-24

https://pmsinformationsystem.forumotion.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum