There are several ways to do this using basic MAX and GROUP BY. Here are a couple of examples.
<pre>create table temp1
(
secid number
, atimestamp date
, acode varchar2(1)
)
/
insert into temp1 values (1,sysdate-1,'a');
insert into temp1 select secid,atimestamp,'b' from temp1;
alter session set nls_date_format = 'dd-mon-rrrr hh24:mi:ss';
select * from temp1;
select *
from temp1
where (secid,acode||':'||atimestamp) in (
select secid,max(acode||':'||atimestamp)
from temp1
group by secid
)
/
select *
from temp1
where (secid,atimestamp,acode) in (
select secid,max(atimestamp),acode
from temp1
where (secid,acode) in (
select secid,max(acode)
from temp1
group by secid
)
group by secid,acode
)
/</pre>
Good luck, Kevin
When you want to use the ‘rownum’ to achieve something like that, you need to use inline views.
Something like this:
But I guess you need one row per secid…
What version of the database are you using ?