Home » SQL & PL/SQL » SQL & PL/SQL » Chained transaction retrieval query
| Chained transaction retrieval query [message #421675] |
Wed, 09 September 2009 13:40  |
namitanamburi
Messages: 35 Registered: March 2009
|
Member |
|
|
These are few transactions and corresponding adjustments made in a bank.
Tran # Type Location Code Date Previous Adj Code
153 TRANSACTION 4 01-SEP-09 12.00.00 AM
155 Adjustment 6 04-SEP-09 04.14.06 PM 153
157 TRANSACTION 4 04-SEP-09 04.31.00 PM
162 Adjustment 6 04-SEP-09 04.50.29 PM 157
169 TRANSACTION 4 30-AUG-09 12.00.00 AM
171 Adjustment 6 30-AUG-09 12.00.00 AM 155
172 TRANSACTION 4 30-AUG-09 12.00.00 AM
What does this mean ?
ACCcode Type Location Code Date Previous Adj Code
153 TRANSACTION 4 01-SEP-09 12.00.00 AM 155 Adjustment 6 04-SEP-09 04.14.06 PM 153
171 Adjustment 6 30-AUG-09 12.00.00 AM 155
The transaction with Acc code 153 has been adjusted twice, the first adjustments acc code is 155 and its previous adj code (153) is equal to acc code of the original transaction.(153).
So the most recent adjustment is
171 Adjustment 6 30-AUG-09 12.00.00 AM 155
I want the out put to be like this.
It means for each transaction, I want to see most recent adjustment, they are linked with previous ADJ Code.
Tran # Type Location Code Date Previous Adj Code
Grouped by date of transaction
sep - 01 - 2008
153 TRANSACTION 4 01-SEP-09 12.00.00 AM
171 Adjustment 6 30-AUG-09 12.00.00 AM 155
sep - 04 - 2008
157 TRANSACTION 4 04-SEP-09 04.31.00 PM
162 Adjustment 6 04-SEP-09 04.50.29 PM 157
Thanks in advance
NAMmu
[added code tags]
[Updated on: Thu, 10 September 2009 03:50] by Moderator Report message to a moderator
|
|
|
|
|
|
|
|
|
|
| Re: Chained transaction retrieval query [message #421752 is a reply to message #421681] |
Thu, 10 September 2009 04:34   |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
Here's a solution:create table test_059 (Tran_code number, tran_Type varchar2(30), Location_Code number(1), tran_Date date, Previous_Adj_Code number);
insert into test_059 values (153 ,'TRANSACTION' ,4 ,to_date('01-SEP-09 12.00.00 AM','dd-MON-yyyy hh.mi.ss AM'), null);
insert into test_059 values (155 ,'Adjustment' ,6 ,to_date('04-SEP-09 04.14.06 PM','dd-MON-yyyy hh.mi.ss AM'), 153);
insert into test_059 values (157 ,'TRANSACTION' ,4 ,to_date('04-SEP-09 04.31.00 PM','dd-MON-yyyy hh.mi.ss AM'), null);
insert into test_059 values (162 ,'Adjustment' ,6 ,to_date('04-SEP-09 04.50.29 PM','dd-MON-yyyy hh.mi.ss AM'), 157);
insert into test_059 values (169 ,'TRANSACTION' ,4 ,to_date('30-AUG-09 12.00.00 AM','dd-MON-yyyy hh.mi.ss AM'), null);
insert into test_059 values (171 ,'Adjustment' ,6 ,to_date('30-AUG-09 12.00.00 AM','dd-MON-yyyy hh.mi.ss AM'), 155);
insert into test_059 values (172 ,'TRANSACTION' ,4 ,to_date('30-AUG-09 12.00.00 AM','dd-MON-yyyy hh.mi.ss AM'), null);
with src as (select * from (
select tran_code,tran_type,tran_date,previous_adj_code
,level row_level
,connect_by_root tran_code cbr_code
,connect_by_root tran_type cbr_type
from test_059
connect by prior tran_code = previous_adj_code
) where cbr_type = 'TRANSACTION')
select tran_code,tran_type,tran_date
from src
where tran_code in (select max(tran_code) keep (dense_rank last order by row_level)
from src
group by tran_type,cbr_code)
order by cbr_code,row_level;
|
|
|
|
|
|
| Re: Chained transaction retrieval query [message #422059 is a reply to message #422030] |
Mon, 14 September 2009 02:57  |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
You can see the test case I posted, with a CREATE TABLE and INSERT statements. I created the first one for you, as you're a relatively new poster - I'm not creating a second test case for you just because you've changed the problem.
When you post a test case, I'll try to look at it for you.
|
|
|
|
Goto Forum:
Current Time: Tue Nov 18 14:00:19 CST 2025
|