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