我是oracle新手,如果这太基础了,对不起。
T1:
ID_SET ID
1 10
1 11
2 12
2 13
T2:
ID Term
11 LONG
12 SHORT
我有表T1和T2,我想从两个表中进行选择,然后插入到另一个表T3中,该表将是:
T3
Long_term Short_term ID_SET
Long 1
Short 2
因此,对于给定的ID_SET,请检查此ID_SET中的ID是否包含“长”或“短”。插入T3的相应列中。ID_SET只能包含“长”和“短”之一。我尝试完全/右/左连接,但是无法正常工作。
感谢您的任何建议!
请尝试以下操作:
insert into t3 (Long_term, Short_term, ID_SET)
select
t2long.term,
t2short.term,
t1.id_set
from t1
left join t2 t2long on t1.id = t2long.id and t2long.term = 'Long'
left join t2 t2short on t1.id = t2short.id and t2short.term = 'Short';
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句