with TABLE_A as(select 'A' as COL1 from dual union allselect 'B' from dual union allselect 'C' from dual), TABLE_B as(select 'A1' as col2 from dual union allselect 'A2' from dual union allselect 'A3' from dual union allselect 'B2' from dual union allselect 'B1' from dual union allselect 'C1' from dual)selectta.col1,(select max(col2) from table_b tb where tb.col2 like ta.col1 || '%') as col2fromtable_a ta;
by 손님 [2012.03.22 21:41:53]-- 쉽게 적용 할 수 있습니다.
WITH a_table AS(SELECT 'A' AS cdFROM dualUNION ALLSELECT 'B' AS cdFROM dualUNION ALLSELECT 'C' AS cdFROM dual ), b_table AS(SELECT 'A1' AS cdFROM dualUNION ALLSELECT 'A2' AS cdFROM dualUNION ALLSELECT 'A3' AS cdFROM dualUNION ALLSELECT 'B1' AS cdFROM dualUNION ALLSELECT 'B2' AS cdFROM dualUNION ALLSELECT 'B3' AS cdFROM dualUNION ALLSELECT 'C1' AS cdFROM dualUNION ALLSELECT 'C2' AS cdFROM dualUNION ALLSELECT 'C3' AS cdFROM dual )SELECT cd,vluFROM (SELECT a.cd,b.cd AS vlu,row_number() OVER (PARTITION BY a.cd ORDER BY b.cd DESC) AS rankingFROM a_table a,b_table bWHERE b.cd LIKE a.cd||'%' )WHERE ranking = 1
by 케빈 [2012.03.23 09:59:08]
답변 감사합니다.
샘플을 가지고 sql을 작성해보니 잘 되네요.
많은 도움이 되었습니다.