Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: oracle rownum
"Shakespeare" <whatsin_at_xs4all.nl> schreef in bericht
news:46cb0657$0$227$e4fe514c_at_news.xs4all.nl...
>
> "odelya" <be.special_at_gmail.com> schreef in bericht
> news:1187705463.959604.54720_at_k79g2000hse.googlegroups.com...
>> Hi,
>>
>> I have a question about rownum which is not mentioned.
>>
>> Lets say that I want to extract a 3 records out of a result where the
>> middle one is the query.
>> For example:
>> I have records:
>> ID Value
>> 1 Hello
>> 2 Hi
>> 3 Wow
>> 4 Shrek
>> 5 Shus
>> 6 What?
>>
>> And I need a query that by receiving ID, it will extract the record
>> with the id and the previous one to that and the next one.
>> For example for selecting ID=4, it will return records: 3,4,5.
>>
>> Is there a way to do it in Oracle?
>>
>
> Go to Morgans Library at http://www.psoug.org and look up the LAG
> function!
>
> Use LAG twice: with offsets of 1 and -1 and OVER (ORDER BY
> <your_date_column>)
>
> Shakespeare
> What's in a LAG?
>
I stand corrected, one LEAD and one LAG, thanks Wiktor!
Shakespeare Received on Tue Aug 21 2007 - 10:39:16 CDT
![]() |
![]() |