队
我希望在oracle中合并3个不同的列,并从源输出目标表。尝试使用UNION运算符,但无法实现和有点混淆带来数学,统计和计算机将其作为一列。请帮助
来源表
**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
答案 0 :(得分: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)
答案 1 :(得分: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