IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Regarding summing up two columns and find difference


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ajay_udl

New User


Joined: 10 Oct 2006
Posts: 29

PostPosted: Tue Mar 10, 2009 9:04 am
Reply with quote

Hi All,

I'm looking for a sql query.

I have columns like TRAN_LID_AM,TRAN_TYPE_CD and EXT_CM_NO.
The column TRAN_TYPE_CD have values 'D' and 'C'.
The EXT_CM_NO represents card-no and we need to sum up all TRAN_LID_AM with TRAN_TYPE_CD as 'D' and again sum up all TRAN_LID_AM with TRAN_TYPE_CD as 'C'. After which we need to output EXT_CM_NO who are having the summed up value of 'D' minus the summed up value of 'C' as positive.

Regards
Ajay.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Mar 10, 2009 9:36 am
Reply with quote

Hello,

In addition to the rules description, it will help if you post some sample columns with values that demonstrate the rules and the output you want from the posted input. Make sure the sample data includes all possibilities and that the sample output corresponds with the input.
Back to top
View user's profile Send private message
murugan_mf

Active User


Joined: 31 Jan 2008
Posts: 148
Location: Chennai, India

PostPosted: Wed Mar 11, 2009 1:44 am
Reply with quote

Hope this query will give some basis
Code:
SELECT A.S1 - B.S2
FROM
(SELECT SUM(TRAN_LID_AM) AS S1 FROM TBL1 WHERE
TRAN_TYPE_CD='D') AS A,
(SELECT SUM(TRAN_LID_AM) AS S2 FROM TBL2 WHERE
TRAN_TYPE_CD='C') AS B


I could not unserstand what so you mean by:
After which we need to output EXT_CM_NO
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Mar 11, 2009 2:00 am
Reply with quote

Hello,

Yes, sample data and the output from that data would be helpful. . .
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Remote Unload of CLOB Columns DB2 6
No new posts Increase the number of columns in the... IBM Tools 3
No new posts Find the size of a PS file before rea... COBOL Programming 13
No new posts Timestamp difference and its average ... DB2 11
Search our Forums:

Back to Top