Searching by Row problem [message #547704] |
Thu, 15 March 2012 18:07 |
|
Lansa
Messages: 5 Registered: March 2012 Location: California
|
Junior Member |
|
|
Data
rec z1 z2 z3 z4 z5
6597 4 5 9 10 23
6596 2 5 7 19 22
6594 9 15 24 30 39
6593 9 13 20 27 39
6592 8 16 25 29 30
6591 2 8 13 29 35
6590 22 28 33 36 37
6589 4 5 11 26 36
6588 10 15 17 20 30
6587 4 9 12 32 39
6586 1 3 5 11 35
6585 3 8 26 30 31
6584 4 11 29 35 37
6583 12 15 33 34 38
6582 2 23 24 37 38
6581 9 14 16 25 33
6580 8 23 29 32 37
6579 14 18 20 24 34
6578 2 32 33 35 38
6577 1 16 18 19 30
6576 4 11 27 32 38
Expected Results
recz1 recz2 recz3 recz4 recz5
6589 6596 6594 6588 6582
6591 6589 6575 6595 6595
6593 6588 6582 6592 6593
6587 6591 6588 6576 6587
6591 6581 6581 6591 6588
I am trying to query the above table to take each column entry, row by row across all columns and search for the next previous occurrence and move the rec number to another column. See expected results. Row 6597 has column entries of 4, 5, 9, 10, 23. The next previous occurrence of 4 was found on row 6589 and moved to column recz1 etc. Can someone help me?
|
|
|
|
Re: Searching by Row problem [message #547706 is a reply to message #547704] |
Thu, 15 March 2012 20:30 |
|
Lansa
Messages: 5 Registered: March 2012 Location: California
|
Junior Member |
|
|
I am sorry!
create table data
(rec number(6),
z1 number(2),
z2 number(2),
z3 number(2),
z4 number(2),
z5 number(2),
recz1 number(6),
recz2 number(6),
recz3 number(6),
recz4 number(6),
recz5 number(6));
|
|
|
|
|
|
|
|
|
|
|
Re: Searching by Row problem [message #547828 is a reply to message #547809] |
Sat, 17 March 2012 01:52 |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
Lansa wrote on Fri, 16 March 2012 22:46What am I doing wrong?
Assuming that rows in table have an order. In reality (and as Michel already remarked), they have no implicit order.
If you want to get result set in specific order, you have to specify rule(s) for determining it - either in ORDER BY clause of the query or entering it in "Sort..." dialog box when watching table data in SQL developer. That is the only way for achieving it. Of course, there must be some column(s) for telling that. How did you know that the row is "first" only from data itself?
As far as I know, SQL Developer shows only first N rows from the result set (default is 50, it may be changed in some settings; I found it under Preferences -> Database -> Advanced Parameters -> Sql Array Fetch Size, but it may differ in your version). Maybe you should get acquainted with the tool you are using, go through its online its help, search online, ...
|
|
|