Live ORACLE

if you are Oracle Developer ,than this Blog most likely will make you happy.

About my Blog

This Blog particularized for Oracle Developers ... you will see interesting Codes for SQL , PL/SQL as well as new ideas for Developer Suite and Client Tools that will help you in your professional life ... and I hope I reach for your satisfaction.

About Me

I'm Hany Freedom , 25 years old , I live in EL-Minia City in Egypt , I'm Moderator at ArabOUG.org the best Arabic Forum for ORACLE on the Net. if you interested to know more about me .... just Click Here.

Select the Nth highest - lowest value from a table

rem execute this code in the Scott SCHEMA
SELECT LEVEL,
Max(sal)
FROM emp
WHERE LEVEL = &nth
CONNECT BY PRIOR sal > sal
GROUP BY LEVEL ;

------------------------------------

rem execute this code in the HR SCHEMA
SELECT LEVEL,
Max(salary)
FROM employees
WHERE LEVEL = &nth
CONNECT BY PRIOR salary > salary
GROUP BY LEVEL
;

SELECT sal ename 
FROM
emp
WHERE sal IN (SELECT Min(sal)
FROM (SELECT DISTINCT sal FROM emp
ORDER BY sal DESC)
WHERE ROWNUM
= &num);

SELECT salary FROM employees e1
WHERE &n IN (SELECT Count(DISTINCT (e2.salary))
FROM employees e2
WHERE e2.salary > e1.salary);

SELECT * FROM   (
SELECT
ROWNUM rn , sal FROM (
SELECT * FROM emp
ORDER BY sal DESC))
WHERE rn = &x;

SELECT salary FROM   (
SELECT salary FROM employees
ORDER BY salary)
WHERE ROWNUM
< &n;

REM TO Find SECOND MAX VALUE FROM A TABLE
SELECT Max(salary) FROM employees WHERE salary IN
(
SELECT Max(salary) FROM employees);

SELECT sal FROM   (
SELECT
DISTINCT sal FROM emp
ORDER BY sal DESC)
WHERE ROWNUM < &&n
MINUS
SELECT sal FROM (
SELECT
DISTINCT sal FROM emp
ORDER BY sal DESC)
WHERE ROWNUM < (&n - 1);

Share/Save/Bookmark

0 comments:

Post a Comment



Newer Posts Older Posts Home Page
 
http://www.dpriver.com/images/sqlpp-banner-2.png

Thanks for reading my Blog ... you Visitor Number :-