Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: SQL query mental block...my solution
Michel Cadot wrote:
> "Glen A Stromquist" <glen_stromquist_at_no_spam_yahoo.com> a écrit dans le message de > news:ddyNc.112177$Rf.52794_at_edtnps84... >
> > > Have a look at: > > first/last_value(more_text) over(partition by some_text order by date_in) > > -- > Regards > Michel Cadot >
Thanks - had a good boo at the first/last_value function, one thing I did notice was that the order by clause seemed to be able to change the results to what I wanted regardless of whether I changed the first/last in the x_value function.
In the end I could still not get it to do what I wanted, however in my searches I found that row_number () (partion on ___ order by ____) was used with x_value for similar results. After much experimentation I could get what I needed, and found that I could drop the x_value altogether and simple use row_number with inline views.
Here is my solution:
,tm9_number tm9 ,datetime_in firstload ,row_number () over (partition by timber_id order by datetime_in asc) rownfrom tm9_form)
,tm9_number tm9 ,datetime_in lastload ,row_number () over (partition by timber_id order by datetime_in desc) rownfrom tm9_form)
Although this query ran pretty fast, if someone has an easier/better way to do this, please share it here. Received on Wed Jul 28 2004 - 16:36:47 CDT
![]() |
![]() |