<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar/1074803565153692547?origin\x3dhttp://innolearning.blogspot.com', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

InnoLearning

Nth highest Retrieval
Sunday, November 4, 2007

Consider a schema EMPLOYEE(name, salary). Now I want to find the employee name having nth highest salary.

For example "Find the name of the employee having 3rd highest salary?"

select salary
from (select rownum rn,b.salary from ( select unique salary from employee a order by salary desc) b)
where rn=N

-- OR --

[using aggregate function (min)]



select min(e.salary)
from(select salary from employee order by salary desc) e
where rownum <= N

Labels: , ,

posted by MIGHTYMAK @ 5:25 AM,




0 Comments:

Post a Comment

<< Home