Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

minimum value in partition to determine column value from other column

763900Apr 1 2011 — edited Apr 1 2011
Hello

Hope the title makes sense!!

I'm having a brain freeze. I have my table 'temp'. What I would like to do is add an extra column which contains the 'act' value which corresponds to the minimum value of 't' for each 'emp' partition. My sql adds a column with the minimum value of 't' ('min_t'), but what I really want is the corresponding 'act' value. Could anyone please advise me how to do this?

Many thanks in advance

Jon
with temp as
(
  select 'Jim' emp, 1 t, 'NR' act from dual union all
  select 'Jim' , 2 , 'NR' from dual union all
  select 'Jim' , 3 , 'NR' from dual union all
  select 'Bob' , 3 , 'Aff' from dual union all
  select 'Bob' , 4, 'NR' from dual union all
  select 'Bob' , 5 , 'NR' from dual union all
  select 'John' , 7 , 'NR' from dual union all
  select 'John' , 8 , 'Aff' from dual union all
  select 'John' , 9 , 'Aff' from dual
)
select temp.*, min (t) over (partition by emp)  min_t
from temp
This post has been answered by Centinul on Apr 1 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 29 2011
Added on Apr 1 2011
7 comments
4,335 views