Reverse the order of column [message #290297] |
Fri, 28 December 2007 05:33 |
neelabh_SE
Messages: 20 Registered: October 2007
|
Junior Member |
|
|
Hello,
I have a table with varchar2 column,say 'abc'.
The task is to create a new table same as above but to reverse the order of “abc” column with first value being replaced with last,second replaced by second-last value so on and so forth.
Please suggest me a way ahead or approach to follow.
thanks,
neel
|
|
|
|
Re: Reverse the order of values in column [message #290307 is a reply to message #290297] |
Fri, 28 December 2007 05:54 |
neelabh_SE
Messages: 20 Registered: October 2007
|
Junior Member |
|
|
Well, I want to reverse the values in column.
Test Case:
Present Scenario :
"zzz" table has below data
ID Name
40000284 Hetlyn
40000285 Bosley
.
.
40030133 Doooley
40030134 Bandy
Expected Solution :
"zzz1",a new table with same structure as "zzz" but reversed value in column Name. Below is the example:
ID Name
40000284 Bandy
40000285 Doooley
.
.
40030133 Bosley
40030134 Hetlyn
thanks,
neel
|
|
|
|
|
|
Re: Reverse the order of column [message #290319 is a reply to message #290297] |
Fri, 28 December 2007 06:17 |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
I would rather ask: what about ID, is it unique?
If so, analytics will give you the desired result
SELECT t1.id, t2.name
FROM
(SELECT id, ROW_NUMBER() OVER (ORDER BY id) rn
FROM zzz) t1,
(SELECT name, ROW_NUMBER() OVER (ORDER BY id DESC) rn
FROM zzz) t2
WHERE t1.rn = t2.rn;
|
|
|
|
|
|
|
|
Re: Reverse the order of column [message #290358 is a reply to message #290297] |
Fri, 28 December 2007 09:05 |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
Oh, I could suspect this is homework as it is of a little real use.
I would describe used steps in words, but was too lazy to do so.
At least I hope you know what analytics is and understand how is it used in this solution.
|
|
|