Hi all,
I got 2 tables : Account_Header and Account_Transaction
with the following fields :
Account_Header : ACCT_CODE, ACCT_NAME
Account_Transaction : ACCT_CODE, TXN_AMT
I want to obtain the a view of the each account with top 3 transactions like this:
ACCT_CODE TXN1 TXN2 TXN3
001 100 50 30
002 200 120 10
003 12 10
004
(in this case 001 and 002 got > 3 txns, 003 got 2 txns and 004 got no txn at all)
Any idea for this query in a more flexible way when the top X (say from top 3 to top 5) account changes? Currently I self-joined the transaction table 3 times to get the result.
Thanks
Joe
I got 2 tables : Account_Header and Account_Transaction
with the following fields :
Account_Header : ACCT_CODE, ACCT_NAME
Account_Transaction : ACCT_CODE, TXN_AMT
I want to obtain the a view of the each account with top 3 transactions like this:
ACCT_CODE TXN1 TXN2 TXN3
001 100 50 30
002 200 120 10
003 12 10
004
(in this case 001 and 002 got > 3 txns, 003 got 2 txns and 004 got no txn at all)
Any idea for this query in a more flexible way when the top X (say from top 3 to top 5) account changes? Currently I self-joined the transaction table 3 times to get the result.
Thanks
Joe