13.05.2013 Views

Thanks for the question regarding "connect by ", versi

Thanks for the question regarding "connect by ", versi

Thanks for the question regarding "connect by ", versi

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

with doc_id and vise versa so when i'm asking <strong>for</strong> <strong>the</strong> related docs to specific doc_id e.g. doc_id<br />

=2 <strong>the</strong> resault should be : ( 5,11,4,9 because of 5 ,6 because of 4 ) and if i change doc_id to any<br />

of <strong>the</strong> resault's value suppose 4 <strong>the</strong> same resault should be <strong>the</strong>re<br />

Followup July 26, 2003 - 12pm Central time zone:<br />

ops$tkyte@ORA920LAP> select *<br />

2 from t<br />

3 start with doc_rel_id = 2<br />

4 <strong>connect</strong> <strong>by</strong> prior doc_id = doc_rel_id;<br />

DOC_ID DOC_REL_ID<br />

---------- ----------<br />

5 2<br />

9 5<br />

11 2<br />

4 2<br />

6 4<br />

To Srikant <strong>for</strong> his urgent query July 27, 2003 - 1pm Central time zone Bookmark | Bottom | Top<br />

Reviewer: A reader<br />

I tried out your scenario - I got a query to get <strong>the</strong><br />

same set of records that you wanted but not in <strong>the</strong> same<br />

order - you can probably tweak it.<br />

Tom may have an even better solution of course!<br />

Menon:)<br />

Here goes:<br />

select x, party, orig_recp, ref_recp, orig_amt, ref_amt<br />

from<br />

(<br />

select a.*, first_value( x) over (partition <strong>by</strong> party order <strong>by</strong> party) first_x,<br />

last_value( x) over (partition <strong>by</strong> party order <strong>by</strong> party) last_x<br />

from<br />

(<br />

select level x, party, orig_recp, ref_recp, orig_amt, ref_amt<br />

from my_level1<br />

where party between 'A0001' AND 'A0003'<br />

<strong>connect</strong> <strong>by</strong><br />

prior orig_recp = ref_recp and<br />

prior party = party<br />

start with ref_recp is null<br />

) a<br />

) b<br />

where x = first_x or<br />

x = last_x;<br />

Skipping Gaps? November 23, 2003 - 12pm Central time zone Bookmark | Bottom | Top<br />

Reviewer: Doug from CT, USA<br />

Tom - is it possible to make a <strong>connect</strong> <strong>by</strong> skip gaps in <strong>the</strong> sequence? Like<br />

SQL> desc a;<br />

Name Null? Type<br />

----------------------------------------- -------- ----------------------<br />

ID NUMBER<br />

PRINUMBER NUMBER<br />

SQL> select * from a;<br />

ID PRINUMBER<br />

---------- ----------<br />

1 2<br />

2 3<br />

3 4<br />

9 10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!