-- CDR 
create table cdr_rating (
  ڵ varchar2(2)
,      varchar2(10)
,      number
);

insert into cdr_rating
select '82', 'A', 100 from dual union all
select '82', 'B', 200 from dual union all
select '82', 'C', 500 from dual union all
select '82', 'D', 300 from dual union all
select '82', 'E', 100 from dual
union all
select '84', 'A', 300 from dual union all
select '84', 'B', 500 from dual union all
select '84', 'C', 400 from dual union all
select '84', ' ', 800 from dual
union all
select '86', 'A', 500 from dual union all
select '86', 'B', 200 from dual union all
select '86', ' ', 700 from dual ;

alter table cdr_rating add
constraint pk_cdr_rating primary key(ڵ, );

-- CDR : ȭ
create table cdr (
  ȭð varchar2(15)
, ڵ varchar2(2)
,      varchar2(10)
);

insert into cdr
select '20050315 010101', '82', 'A' from dual union all
select '20050315 020101', '82', 'B' from dual union all
select '20050315 030101', '82', 'C' from dual union all
select '20050315 040101', '84', 'A' from dual union all
select '20050315 050101', '84', 'B' from dual union all
select '20050315 060101', '84', 'C' from dual union all
select '20050315 070101', '84', 'D' from dual union all
select '20050315 080101', '84', 'E' from dual union all
select '20050315 090101', '86', 'A' from dual union all
select '20050315 100101', '86', 'B' from dual union all
select '20050315 110101', '86', 'C' from dual union all
select '20050315 120101', '86', 'D' from dual union all
select '20050315 130101', '86', 'E' from dual union all
select '20050315 140101', '86', 'F' from dual ;

alter table cdr add
constraint pk_cdr primary key(ȭð, ڵ, );


select ڵ, '''' ||  || '''',  from cdr_rating ;

select * from cdr;


select /*+ ordered use_nl(r) */
       c.ȭð, c.ڵ, c., r.
from   cdr c, cdr_rating r
where  c.ȭð like '20050315%'
and    c.ڵ = r.ڵ
and    c.     = r. ;


select /*+ ordered use_nl(r) */
       c.ȭð, c.ڵ, c., r.
from   cdr c, cdr_rating r
where  c.ȭð like '20050315%'
and    c.ڵ = r.ڵ(+)
and    c.     = r.(+) ;

select /*+ ordered use_nl(r) */
       c.ȭð, c.ڵ, c., r.
from   cdr c, cdr_rating r
where  c.ȭð like '20050315%'
and    (r.ڵ, r.) =
       (select c.ڵ, max()
        from   cdr_rating
        where  ڵ = c.ڵ
        and      in (' ', c.) ) ;


-- 9i
select /*+ ordered use_nl(r) index(r pk_cdr_rating) */ 
       c.ȭð, c.ڵ, c., r.
from   cdr c, cdr_rating r
where  c.ȭð like '20050315%'
and    (r.ڵ, r.) = 
       (select /*+ use_concat */ c.ڵ,  
        from   cdr_rating
        where  ڵ = c.ڵ
        and      in (' ', c.)
        and    rownum <= 1) ;

-- 10g 
select /*+ ordered use_nl(r) index(r pk_cdr_rating) */ 
       c.ȭð, c.ڵ, c., r.
from   cdr c, cdr_rating r
where  c.ȭð like '20050315%'
and    (r.ڵ, r.) = 
       (select /*+ use_concat(@subq 1) qb_name(subq) ordered_predicates */ c.ڵ,  
        from   cdr_rating
        where  ڵ = c.ڵ
        and      in (' ', c.)
        and    rownum <= 1) ;

-- 10g 
select /*+ ordered use_nl(r) rowid(r) */ 
       c.ȭð, c.ڵ, c., r.
from   cdr c, cdr_rating r
where  c.ȭð like '20050315%'
and    r.rowid = 
     (select /*+ use_concat(@subq 1) qb_name(subq) ordered_predicates */ rowid 
      from   cdr_rating
      where  ڵ = c.ڵ
      and         in (' ', c.)
      and    rownum <= 1
     ) ; 


