Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

JOIN query in DB2

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
venki123

New User


Joined: 05 Feb 2008
Posts: 1
Location: pune

PostPosted: Wed Feb 06, 2008 10:03 am    Post subject: JOIN query in DB2
Reply with quote

Table A

order# receipt line# cost-code Cost-rate

234 1 1 xx .22
234 1 1 xy .11
234 1 1 xz .33
234 1 2 xx .22
234 1 2 xz .33

234 2 1 xx .22
234 3 1 xx .22
234 3 2 xx .22
234 3 2 xy .11
234 3 4 xz .33


Table B


order# receipt line# line-qty

234 1 1 10
234 1 2 6
234 2 1 10
234 3 1 9
234 3 2 12
234 3 4 15


I have TWO tables A & B with above colums.

Table 1:- Order contains receipt, receipt may contain multiple lines. Again line will contains different associated cost-codes.

Table 2:- each line contains quantity


I want to calcalualte the one recipt value of for all cost codes associated with it.

Eg:-
________1(10)--xx,xy,xz
|
1 receipt__________|
|
|________2(06)--xx,xz.


receipt 1 has 2 lines(of qunatity 10 & 6 respectively ) & each line has differnt cost codes.


Suppose I want receipt 1 value in the order 234 for cost-code xx.


receipt 1 value @ cost code xx :- (10X.22) + (6X.22)

{line 1 calculation ) + {line 2 calculation }

same for all

receipt 1 value @ cost code xx :- (10X.22) + (6X.22) = A
receipt 1 value @ cost code xy :- (10X.33) + (6X.33) = B
receipt 1 value @ cost code xz :- (10X.11) = C

nOW Total receipt value is A+B+c.

So that I can calculate all the recips value one by one.


Can you give me an idea how can i write a querry for this. Please note this should be in PERFORM loop.

Thanks for your help.
Back to top
View user's profile Send private message

bbessa

New User


Joined: 03 Aug 2006
Posts: 13
Location: Brazil

PostPosted: Thu Feb 07, 2008 1:31 am    Post subject:
Reply with quote

Take a look a this article: How to Use GROUP BY with Distinct Aggregates and Derived tables

I think it'll help you.

Bernardo
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us