Oracle中将多行多列转换为一条记录 [英] Convert multiple rows with multiple column into one record in Oracle
本文介绍了Oracle中将多行多列转换为一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Oracle SQL 查询中,我们得到 40 条记录,其中 13 列.我想将所有这些记录合并到一列意味着1条记录中的40 * 13 = 520列.例如- 具有很少记录的样本表
In Oracle SQL query we got 40 records having 13 columns. I want to merge all these records into one column means 40 * 13 = 520 column in 1 record. Eg- Sample table having few records
col1 col2 city cntry conti
1 abc NYC USA NA
2 def LON UK EU
3 xyz DUB UAE ASIA
然后在合并所有记录&进入一个记录然后它应该像下面的一个-
then after merge all the records & get into the one record then it should be like the below one-
col1 col2 city cntry conti col1 col2 city cntry conti col1 col2 city cntry conti
1 abc NYC USA NA 2 def LON UK EU 3 xyz DUB UAE ASIA
推荐答案
如果 col1
列包含唯一值,那么您可以使用 pivot
:
If column col1
contains unique values then you could use pivot
:
select *
from t
pivot (max(col1) col1, max(col2) col2, max(city) city, max(cntry), max(conti) conti
for col1 in (1, 2, 3))
这篇关于Oracle中将多行多列转换为一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文