I need an sql select statement that would transform
1
2
3
4
into 1 2 3 4
Without using PIVOT functions as I am running oracle 10 database. Searched quite a lot on the Internet but surprisingly found nothing.
Little help?
You can do a pivot almost as efficiently using a cross join:
select max(case when seqnum = 1 then t.col end) as col1,
max(case when seqnum = 2 then t.col end) as col2,
max(case when seqnum = 3 then t.col end) as col3,
max(case when seqnum = 4 then t.col end) as col4
from (select t.*, row_number() over (order by NULL) as seqnum
from t
) t
select for addition columns. But you cannot vary the number (they will be populated with NULL if there is no value). Alternatively, you could use list_agg to put them all in one column, with delimiters.