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

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

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

View previous topic View next topic Go down

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

Post  maran on 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
Admin

Posts : 442
Join date : 2009-07-24

View user profile http://pmsinformationsystem.forumotion.net

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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