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

DB2 Column Fuction Compare


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

New User


Joined: 22 Sep 2009
Posts: 5
Location: Pune

PostPosted: Wed Nov 18, 2009 1:05 pm
Reply with quote

Suppose there are 2 tables A and B

I want to use DB2 column function(SUM) on one field of table A
and this SUM is to be compared with one field from table B.

how i can accomplish this?
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Wed Nov 18, 2009 1:47 pm
Reply with quote

you can use subselect or having clause.
This depends on how Table A and B are grouped and/or joined
Back to top
View user's profile Send private message
sachin_star3
Warnings : 1

New User


Joined: 30 Sep 2006
Posts: 78
Location: pune

PostPosted: Thu Nov 19, 2009 12:39 am
Reply with quote

please try the below query:

select * from table b where salary in (
select sum(salary) from table a where emp name ='vinod'
group by salary)
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: Thu Nov 19, 2009 1:13 am
Reply with quote

Hello,

How does this query compare the sum to a column from the other table?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Nov 19, 2009 1:57 am
Reply with quote

Quote:
emp name ='vinod'


Congratulations sachin_star3,

Wednesday must be psychic day for you!
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 Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
No new posts first column truncated in search result IBM Tools 13
Search our Forums:

Back to Top