2014-08-31 5 views
1

팀,oracle에서 두 개의 다른 열을 병합하는 방법

oracle에서 3 개의 다른 열을 병합하고 원본에서 대상 테이블로 출력하려고합니다. UNION 연산자를 사용했지만, 달성 할 수 있고 혼란 조금 한 column.Please 도움말로 가져 수학, 통계 및 컴퓨터를 가져

소스 테이블

**STUDENT_ID MATHS STATS COMPUTERS** 
1   90  80  70 
2   60  50  70 

대상 테이블

**STUDENT_ID SUBJECT MARKS** 
    1    maths  90 
    1    stats  80 
    1    computers 70 
    2    maths  60 
    2    stats  50 
    2    computers 70 

답변

4

이렇게하면 예상 한 결과를 얻을 수 있습니다.

insert into target_table 
(select student_ID,'maths',MATHS from source_table 
union all 
select student_ID,'stats',STATS from source_table 
union all 
select student_ID,'computers',COMPUTERS from source_table) 
0

이것은 나를 위해 일했습니다 !!

insert into targettable (student_id , Subjects ,marks) 
select student_id, 'Maths', maths from sourcetable 
union 
select student_id, 'Stats', stats from sourcetable 
union 
select student_id,'Computer',computer from sourcetable