Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: nice sql problem
mike2322_at_hotmail.com (Mike Liu) wrote in message news:<2262aa8e.0201291122.6ab233fd_at_posting.google.com>...
> devnull_at_ronr.nl (Ronald) wrote in message news:<67ce88e7.0201290442.2bd6ad09_at_posting.google.com>...
> > given table contains
<snip>
> Try this,
> select min(a), max(b)
> from (
> select a, b, rownum-level gp
> from z
> connect by a = prior b
> start with a not in (
> select b from z
> )
> )
> group by gp
> /
I think this is also working and also in others than oracle:
select min(aa.a),min(bb.b)
from
(
select a,0 b, rownum rx
from z a
where not exists (select 'x'
from z b where b.b = a.a)
from z b where a.b = b.a) ) aa,
from z b where b.b = a.a)
from z b where a.b = b.a) ) bb
It's not as elegant but it works - I think Needs an index on a and on b for optimal performance and can still be improved.
Ronald.