troubleshooting Question

Oracle 9i - Select Two rows into columns

Avatar of JDCam
JDCam asked on
Oracle DatabaseSQL
15 Comments1 Solution368 ViewsLast Modified:
Experts,
I have a simple table (My_Table). The table records movement between accounts. For each movement, there are always 2 rows (a debit and a credit). I need to write a query to return 1 row per movement with the debit and credit accounts in colums

example table
TRANS_ID      REF_NUM       ACCT      AMT
0001            ABC123            F1234      -107
0001            ABC123            X666      107
0002            XYZ456            Q2525      -91
0002            XYZ456            D2000      91
0003            ZZZ222            y1234      198
0003            ZZZ2222              F1234      -198

Query should return like this

TRANS_ID      REF_NUM       FROM_ACCT      FROM_AMT       TO_ACCT            TO_AMT
0001            ABC123            F1234            -107             X666            107
0002            XYZ456            Q2525            -91                     D2000            91
0003            ZZZ222            F1234            -198                   y1234            198

Please help
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 15 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros