Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Select Query with diagonally matching columns

Satyam ReddyDec 6 2011 — edited Dec 6 2011
hi

the following is the table struncture and insert statements
create table emp_trans values (empno number , emptran_no number, prev_amount number, current_amount number)

insert into emp_trans values(102,109,0,20);
insert into emp_trans values(102,119,10,20);
insert into emp_trans values(102,129,20,30);
insert into emp_trans values(102,139,30,0);

insert into emp_trans  values(201,101,0,20);
insert into emp_trans values(201,110,20,30);
insert into emp_trans values(201,120,0,30);
insert into emp_trans values(201,130,30,20);
insert into emp_trans values(201,140,0,20);
In the table we can see some mappings as follows

The data is on empno basis.
we have 2 employees with empno 201 and 102 . Each empno has different emptrans_no. Need not be in an sequence.
we need to select the set of records where prev_amount column matches with the current_amount column values for
the previous record for every individual empno.

prior to that the following basic select statement can be considered
select * from emp_trans  order by empno , emptran_no
for ex:

emp no 102 emptran_no 129 prev_amount column having values of 20 matches with the current_amount column having values 20
with emptran_no 119.

for empno 201 with emptran_no 110 we can see the prev_amount column having value 20 matched with current_account column havig values of 20
of previous emptran_no 101 for the same empno 201.

something like we need to see the diagnally mathced values.

Any help on such query most welcome.

Regards,
This post has been answered by Frank Kulash on Dec 6 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 3 2012
Added on Dec 6 2011
4 comments
595 views