问题
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
回答1:
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))
SQLFiddle demo
来源:https://stackoverflow.com/questions/47993215/convert-multiple-rows-with-multiple-column-into-one-record-in-oracle