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

Home -> Community -> Usenet -> c.d.o.misc -> Re: queyr (maximum)

Re: queyr (maximum)

From: bung ho <bung_ho_at_hotmail.com>
Date: 23 Jul 2003 17:46:43 -0700
Message-ID: <567a1b1.0307231646.15e6e97f@posting.google.com>


"Max" <papouasied_at_yahoo.com> wrote in message news:<3f1dbf7b$0$15328$626a54ce_at_news.free.fr>...
> hi,
>
> I want the transactions and levels which level is maximum and version is
> maximum, knowing the version has priority (version > level)
>
> Transaction Level Version code
>
> teti 0 1 A
>
> titi 1 2 A
>
> tuta 0 1 B
>
> tata 1 1 B
>
> toto 0 1 C
>
> tuto 1 1 C
>
>
>
>
>
> gives:
>
>
>
> titi 1 2 A
>
> tata 1 1 B
>
> tuto 1 1 C
>
>
> The query:
> select a.transaction,max(version),max(level), a.code,
> from ma_table a
> group by a.transaction, a.level
>
>
> gives wrong results of course.
>
>
>
> Thanks for your help

you don't say what happens if two different transactions have the same level and version for the same code, but here goes:

select code,

       substr(mess, 21) transaction,
       to_number(substr(mess, 1, 10)) lvl,
       to_number(substr(mess, 11, 10)) version
from (select code,
             max(lpad(lvl, 10, '0') ||
                 lpad(version, 10, '0') ||
                 transaction) mess
      from t
      group by code)

if you need to, replace 10 with some x where x > the maximum number of digits level and version can be, and replace 21 with 2x + 1.

also, this only works for (positive) whole integers for level and version. Received on Wed Jul 23 2003 - 19:46:43 CDT

Original text of this message

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