Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Please explain this query
shihab schrieb:
> This is the query to findout Nth Max (Highest) value from a table
>
> SELECT sal from emp t
select 'sal' from table emp
(alias emp as 't' so we can reference to it later on)
> WHERE &n =
where <n> is equal to
> (SELECT COUNT(sal)
the amount of 'sal' there is
> FROM (SELECT DISTINCT sal FROM emp)
in a 'pseudo table' with distinct 'sal's - no duplicates
> WHERE t.sal<=sal);
where 'sal' from the 'pseudo table' is larger or equal to a 'sal' from the aliased, first mentioned, emp
Ehm... Didn't really make you wiser, eh?
What it does is calculating for which 'sal' there is exactly (n - 1) distinct 'sal's of lower value, making 'sal' itself the nth highest value.
Ok, let someone with educational talents take over...
/impslayer, aka Birger Johansson Received on Thu Oct 13 2005 - 07:07:29 CDT
![]() |
![]() |