SQL TIP: To find out the N th highest and N th lowest values from table.
Page 1 of 1
SQL TIP: To find out the N th highest and N th lowest values from table.
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)
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)
Similar topics
» What? A high speed table is not a "thing" in itself. A high speed table is a normal LANSA file definition that has its "high speed" flag set to YES. • A LANSA file definition flagged as high speed table is actually implemented as a normal database file.
» How do we find the last IPL details?
» Find String PDM
» Find a String in a DBF records.
» How to find the Version in AS/400 system
» How do we find the last IPL details?
» Find String PDM
» Find a String in a DBF records.
» How to find the Version in AS/400 system
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum