如何将多列合并为具有多行的单个列. [英] how to merge multiple columns into a single column with multiple rows.
问题描述
请问有人可以帮我吗?
我想将多列(例如4列)合并为具有多行的单列.
例如:
数据
Col1 Col2 Col3 Col4
1/1/2011 1/3/2011 1/3/2011 1/3/2011
1/2/2011 1/3/2011 1/3/2011 1/3/2011
1/3/2011 1/3/2011 1/3/2011 1/3/2011
我想要以上的输出为:
日期
2011年1月1日
2011/1/2
1/3/2011
2011年1月1/3< ==该数据在COL2中重复.我要在行中输入不同的数据.
2011年1月1/3< ==此数据在COL3中重复.我要在行中输入不同的数据.
2011年1月1/3< ==该数据在COL4中重复.我要在行中输入不同的数据.
请帮助我.
Please can anyone help me for the following?
I want to merge multiple columns(eg. 4colums) into a single column with multiple rows.
for eg:
data
Col1 Col2 Col3 Col4
1/1/2011 1/3/2011 1/3/2011 1/3/2011
1/2/2011 1/3/2011 1/3/2011 1/3/2011
1/3/2011 1/3/2011 1/3/2011 1/3/2011
i want output for the above as:
Date
1/1/2011
1/2/2011
1/3/2011
1/3/2011 <== this data are duplicate in COL2. i want distinct data in row.
1/3/2011 <== this data are duplicate in COL3. i want distinct data in row.
1/3/2011 <== this data are duplicate in COL4. i want distinct data in row.
Please help me.
推荐答案
第一个 ^ ]查询可用于合并列.然后使用DISTINCT关键字只选择每个值一次.
First a union[^] query can be used to merge the colums. Then use the DISTINCT keyword to only select each value once.
您可以看看PIVOT和UNIPIVOT.
请参见此处 [此处 [ ^ ]是另一个示例.
You could have a look at PIVOT and UNIPIVOT.
See here[^].
Here[^] is another example.
这篇关于如何将多列合并为具有多行的单个列.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!