Need the query

Need the query

 

  


Hi,

I am new to DB2 and would appreciate any help with the SQL query.

I have to write a balancing script which would compare the column (AMT) of the same Balance ID and its corresponding step_keys and need your help with this.


My table data is as below:


BAL_ID, STEP_KEY, COMPANY, DAC, STATE, TYPE, AMT, PROC_DATE

1, 5, 1, 4, IL, PYMT, 54001.23, 2007-11-28

1, 2, 1, 4, IL, PYMT, 54001.24, 2007-11-28



2, 3, 1, 4, IL, RSV, 100.05, 2007-11-28

2, 4, 1, 4, IL, RSV, 100.25, 2007-11-28

2, 3, 1, 5, IL, PYMT, 2201, 2007-11-28

2, 4, 1, 5, IL, PYMT, 2201.5, 2007-11-28



Say for example: For every BAL_ID, there are two step_keys and I have to compare the AMT of these two steps keys and display them as AMT1 and AMT2 if they don't match.



For BAL_ID 1, I have to compare 540001.23 with 54001.24 for step keys 5 & 2 respectively.



Final output based on the above data should be like



BAL_ID COMPANY DAC STATE TYPE STEP_KEY1 AMT1 STEP_KEY2 AMT2 PROC_DATE

1 1 4 IL PYMT 5 54001.23 2 54001.24 2007-11-28

2 1 4 IL RSV 3 100.05 4 100.25 2007-11-28

2 1 5 il RSV 3 2201 4 2001.5 2007-11-28



Thanks,

Pinki








The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

www.wipro.com

DB2 & UDB email list listserv db2-l LazyDBA home page