create table  
as 
select  empno ȣ, ename , 'C70' ȸ
     , '' , '...' ּ, '123-' || empno ó
     , to_char(to_date('20050101','yyyymmdd')+rownum*20000,'yyyymmdd') 񽺸
from    emp
where   rownum <= 10;

create index _idx01 on (ȸ);

create table ü̷
as
select a.ȣ, b., b.ü, b.üݾ
from   a
    ,(select to_char(to_date('20050101', 'yyyymmdd')+rownum*2, 'yyyymmdd') 
           , round(dbms_random.value(1, 12)) ü
           , round(dbms_random.value(100, 1000)) * 100 üݾ
      from   dual
      connect by level <= 100000) b;


create index ü̷_idx01 on ü̷(ȣ, );

select a., a., a.ּ, a.ó, b.üݾ
from    a, ü̷ b
where  a.ȸ = 'C70'
and    b.ȣ = a.ȣ
and    b. = (select /*+ no_unnest */ max()
                     from   ü̷  
                     where  ȣ = a.ȣ
                     and     <= a.񽺸);


select a., a., a.ּ, a.ó
      ,(select /*+ index_desc(b ü̷_idx01) */ üݾ
        from   ü̷ b
        where  b.ȣ = a.ȣ
        and    b. <= a.񽺸
        and    rownum <= 1) üݾ
from    a
where  ȸ = 'C70';


select , , ּ, ó
     , to_number(substr(ü, 3)) üݾ
     , to_number(substr(ü, 1, 2)) ü
from  (select a., a., a.ּ, a.ó
            ,(select /*+ index_desc(b ü̷_idx01) */ 
                     lpad(ü, 2) || üݾ
              from   ü̷ 
              where  ȣ = a.ȣ
              and     <= a.񽺸
              and    rownum <= 1) ü
       from    a
       where  ȸ = 'C70'
);

select , , ּ, ó
     , to_number(substr(ü, 11)) üݾ
     , to_number(substr(ü, 9, 2)) ü
from  (select a., a., a.ּ, a.ó
            ,(select max( || lpad(ü, 2) || üݾ)
              from   ü̷ 
              where  ȣ = a.ȣ
              and     <= a.񽺸) AS ü
       from    a
       where  ȸ = 'C70'
);

select /*+ ordered use_nl(b) rowid(b) */ a.*, b.üݾ, b.ü
from  (select a., a., a.ּ, a.ó
            ,(select /*+ index_desc(b ü̷_idx01) */ rowid rid
              from   ü̷ b
              where  b.ȣ = a.ȣ
              and    b. <= a.񽺸
              and    rownum <= 1) rid
       from    a
       where  ȸ = 'C70') a, ü̷ b
where  b.rowid = a.rid;


select /*+ ordered use_nl(b) rowid(b) */
       a., a., a.ּ, a.ó, b.üݾ, b.ü
from    a, ü̷ b
where  a.ȸ = 'C70'
and    b.rowid = (select /*+ index(c ü̷_idx01) */ rowid
                  from   ü̷ c
                  where  c.ȣ = a.ȣ
                  and    c. <= a.񽺸
                  and    rownum <= 1);

                  
select /*+ full(a) full(b) full(c) use_hash(a b c) no_merge(b) */
       a., a., a.ּ, a.ó, c.üݾ, c.ü
from    a
     ,(select ȣ, max() 
       from   ü̷
       where   <= to_char(sysdate, 'yyyymmdd')
       group by ȣ) b, ü̷ c
where  b.ȣ = a.ȣ
and    c.ȣ = b.ȣ
and    c. = b.;


select a., a., a.ּ, a.ó
     , to_number(substr(ü, 11)) üݾ
     , to_number(substr(ü, 9, 2)) ü
from    a
     ,(select ȣ, max( || lpad(ü, 2) || üݾ ) ü
       from   ü̷
       where   <= to_char(sysdate, 'yyyymmdd')
       group by ȣ) b
where  b.ȣ = a.ȣ;

select a., a., a.ּ, a.ó, b.üݾ, b.ü
from    a
     ,(select ȣ, üݾ, ü, 
            , row_number() over (partition by ȣ order by  desc) no
       from   ü̷
       where   <= to_char(sysdate, 'yyyymmdd')) b
where  b.ȣ = a.ȣ
and    b.no = 1;

select a., a., a.ּ, a.ó, b.üݾ, b.ü
from    a
     ,(select ȣ, üݾ, ü, 
            , max() over (partition by ȣ) max_dt
       from   ü̷
       where   <= to_char(sysdate, 'yyyymmdd')) b
where  b.ȣ = a.ȣ
and    b. = b.max_dt;










