Re: SQL Question

From: Jusung Yang <JusungYang_at_yahoo.com>
Date: 4 Oct 2002 16:30:51 -0700
Message-ID: <130ba93a.0210041530.6ca7fab1_at_posting.google.com>


rownum probably would not satisfy the poster's requirements, though the analytical function row_number will solve his problem eazily. For example:

SQL> select c1, max(c3) maxc3 from t1 group by c1,c2;

a           8
a           9
a           9
b           4
b           5
c           2
c           3
d           2
d           3
e           2
e           3
f           2
f           3
g           2
g           3
h           2
h           3

17 rows selected.

SQL> select c1, maxc3 from (select c1, maxc3, row_number() over (partition by c1 order by c1) rank
  2 from (select c1, max(c3) maxc3 from t1 group by c1,c2)) where rank=1;

a           8
b           4
c           2
d           2
e           2
f           2
g           2
h           2

8 rows selected.

SQL>

  • Jusung Yang

"Steve M" <steve.mcdaniels_at_vuinteractive.com> wrote in message news:<ankhg7$2pq$1_at_spiney.sierra.com>...
> select * from
> (
> <insert your query here>
> )
> where rownum = 1
>
Received on Sat Oct 05 2002 - 01:30:51 CEST

Original text of this message