I need some help in formulating data in Oracle. I will give an example –
I have a Table Customer with Name column.
Customer
Name
Ashish
Amit
Sunny
Bob.
I want to get output in the format where names at odd number are adjacent to names at even number; output would be
Customer
Name1 Name2
Ashish Amit
Sunny Bob
and so on…
I tried following query but it doesn’t give me the required output.
select name,
case Mod(rownum,2)
when 1 then name
end col1,
case Mod(rownum,2)
when 0 then name
end col2
from Customer
This ia basically a
PIVOTof the data but Oracle10g does not have the pivot function so you will have to replicate it using an aggregate and aCASEstatement. If you apply therow_number() over()as well you can transform the data into the result that you want.See SQL Fiddle with Demo
Result: