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
 

 

Want to find out Sum of two rows

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

New User


Joined: 09 Dec 2008
Posts: 23
Location: india

PostPosted: Wed Jul 22, 2009 3:23 pm    Post subject: Want to find out Sum of two rows
Reply with quote

Hi,

We have two tables with following data:

table 1
col1 col2 col3 col4
1069 5 AC Active
1069 6 AC Active
1070 5 AC Active
1070 6 AC Active
1070 6 AC Inactive

table 2
col1 col2 col5
1069 5 112.00
1069 5 114.00
1069 6 124.00

Col1 & Col2 are common in both the tables so can be used in Joins.

Now we need to write a query and select data from both the tables with following conditions:
-->table 1 having Col1 = 1069
-->table 1 having Col4 as Active
-->sum of Col5
-->Maximum of Col2
Back to top
View user's profile Send private message

expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Wed Jul 22, 2009 3:31 pm    Post subject:
Reply with quote

Quote:
Now we need to write a query and select data from both the tables with following conditions:

Please show us what you have coded along with what your problems are
Back to top
View user's profile Send private message
replytovishu

New User


Joined: 09 Dec 2008
Posts: 23
Location: india

PostPosted: Wed Jul 22, 2009 3:38 pm    Post subject:
Reply with quote

SELECT SUM(B.COL5)
FROM TABLE1 A
INNER JOIN TABLE2 B
ON A.COL1 = B.COL1
AND A.COL2 = B.COL2
WHERE A.COL1 = 1069
AND A.COL4 = 'ACTIVE'
GROUP BY B.COL2

I Have coded this query.
It is giving individual sum of the groups.
But the need is to find the sum of max of all the groups selected by join and where condtion.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Jul 22, 2009 7:49 pm    Post subject:
Reply with quote

group by col1 and not col2 ...
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Jul 22, 2009 7:52 pm    Post subject:
Reply with quote

Quote:


-->sum of Col5
-->Maximum of Col2



Quote:


But the need is to find the sum of max of all the groups selected by join and where condtion.



contradiction ?
Back to top
View user's profile Send private message
replytovishu

New User


Joined: 09 Dec 2008
Posts: 23
Location: india

PostPosted: Wed Jul 22, 2009 9:06 pm    Post subject:
Reply with quote

Yeah i know it seems contradiction
Need to find out maximum value from a group and finally need to do a summation.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Jul 22, 2009 9:10 pm    Post subject:
Reply with quote

did you try your query with change in group by ?
Back to top
View user's profile Send private message
knn9413

New User


Joined: 23 Jul 2009
Posts: 17
Location: US

PostPosted: Thu Jul 23, 2009 7:57 pm    Post subject:
Reply with quote

try this

select b.col1, max(b.col2), sum(b.col5)
from table1 as a,
table2 as b
where a.col1 = b.col1
and a.col1 = 1069
and a.col4 = 'ACTIVE'
group by b.col1
Back to top
View user's profile Send private message
Raghu navaikulam

Active User


Joined: 27 Sep 2008
Posts: 193
Location: chennai

PostPosted: Fri Jul 24, 2009 2:31 pm    Post subject: Reply to: Want to find out Sum of two rows
Reply with quote

Hi replytovishu

Post your expected result in the forum.

Regards
Raghu
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 compare 2 rows within the same file ram_vizag SYNCSORT 7 Wed Jun 14, 2017 12:34 am
No new posts find RACF group for access to spooled... jzhardy JCL & VSAM 1 Mon May 08, 2017 11:46 am
No new posts To find out size allocated to a seque... ashek15 JCL & VSAM 15 Thu Apr 27, 2017 9:42 am
No new posts To display values of multiple rows in... vinu78 DB2 2 Thu Mar 09, 2017 1:20 pm
No new posts how to send just 10 rows in a CICS sc... Megha Gupta CICS 5 Thu Feb 23, 2017 6:57 pm


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