Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Please explain this query

Re: Please explain this query

From: impslayer <impslayer_at_hotmail.com>
Date: 13 Oct 2005 05:07:29 -0700
Message-ID: <1129205249.796993.228320@o13g2000cwo.googlegroups.com>

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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US