2017-06-01 47 views
0

我想转置数据集从广泛到长。我已经完成了这项工作是SAS,但对此尚属陌生。理想情况下,我希望每个ID和代码都有一个唯一的行。不知道是否可以一步或多步完成,无论哪种方式对我都没问题。我的数据看起来像这样。蟾蜍为Oracle - 重塑从广泛到长

ID code1 code2 code3 
1  abc  def  ghi 
1  abc  xyz  def 
2  zyx  abc  mno 

,我希望它看起来像

ID Code_concat 
1 abc 
1 def 
1 ghi 
1 xyz 
2 zyx 
2 abc 
2 mno 

任何意见,将不胜感激,谢谢!

+0

要么多个集合运算符('union' /'工会all'),或者如果Oracle版本允许[逆透视](HTTP:// www.oracle.com/technetwork/articles/sql/11g-pivot-097235.html)操作符,它基本上在封面下执行相同操作。 –

回答

1

给定要删除重复最简单的方法是union

select id, code1 as code_concat from t union 
select id, code2 as code_concat from t union 
select id, code3 as code_concat from t; 
+0

非常感谢 – bmb1020