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
 

 

How to get the SUM value of the below query

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

New User


Joined: 15 Dec 2005
Posts: 21

PostPosted: Tue Sep 22, 2009 1:36 am    Post subject: How to get the SUM value of the below query
Reply with quote

SELECT (MAX(VV_MRC_BASE_AMT) + MAX(VV_NRC_BASE_AMT))
FROM TAEVV.VV_CMPT_OVRD_RNG
WHERE VV_TRCK_ORDR_NUM = 8523



Out put is displaying 5 rows total of those two fields

12222
1700
23000
2700
10000

But i want to get the to total of all those 5 rows count.

IS it posible in this single query ?
Back to top
View user's profile Send private message

dick scherrer

Site Director


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

PostPosted: Tue Sep 22, 2009 1:45 am    Post subject:
Reply with quote

Hello,

You might try:
SELECT SUM(MAX(VV_MRC_BASE_AMT) + MAX(VV_NRC_BASE_AMT)) etc. . .
Back to top
View user's profile Send private message
vijayprabu

New User


Joined: 15 Dec 2005
Posts: 21

PostPosted: Tue Sep 22, 2009 2:11 am    Post subject:
Reply with quote

dick scherrer wrote:
Hello,

You might try:
SELECT SUM(MAX(VV_MRC_BASE_AMT) + MAX(VV_NRC_BASE_AMT)) etc. . .



HI -

I am getting the Below error
,
, DSNT408I SQLCODE = -112, ERROR: THE OPERAND OF AN AGGREGATE FUNCTION
, INCLUDES AN AGGREGATE FUNCTION OR A SCALAR FULLSELECT
, DSNT418I SQLSTATE = 42607 SQLSTATE RETURN CODE
, DSNT415I SQLERRP = DSNXOOS1 SQL PROCEDURE DETECTING ERROR
, DSNT416I SQLERRD = -220 0 0 -1 0 0 SQL DIAGNOSTIC INFORMATION
, DSNT416I SQLERRD = X'FFFFFF24' X'00000000' X'00000000'
, X'FFFFFFFF' X'00000000' X'00000000' SQL DIAGNOSTIC
,
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Tue Sep 22, 2009 2:38 am    Post subject: Reply to: How to get the SUM value of the below query
Reply with quote

Hello,

Looks like my bad icon_redface.gif

I'm not connected, so i didn't run a test. . .

Sorry for the mis-queue.

d
Back to top
View user's profile Send private message
Raghu navaikulam

Active User


Joined: 27 Sep 2008
Posts: 186
Location: chennai

PostPosted: Tue Sep 22, 2009 11:13 am    Post subject: Reply to: How to get the SUM value of the below query
Reply with quote

Hi Vijayprabu

Try this query

Code:
SELECT SUM(AMT) FROM (
(SELECT MAX(VV_MRC_BASE_AMT)  AS AMT FROM TAEVV.VV_CMPT_OVRD_RNG WHERE VV_TRCK_ORDR_NUM = 8523
UNION ALL 
SELECT MAX(VV_NRC_BASE_AMT)  AS AMT FROM TAEVV.VV_CMPT_OVRD_RNG WHERE VV_TRCK_ORDR_NUM = 8523)
AS AMT;


Hope this will help you
Regards
Raghu
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue Sep 22, 2009 4:08 pm    Post subject:
Reply with quote

Alternatively ..

Code:


SELECT A+B AS SUM FROM
(SELECT MAX(VV_MRC_BASE_AMT) AS A , MAX(VV_NRC_BASE_AMT)  AS B
FROM TAEVV.VV_CMPT_OVRD_RNG WHERE VV_TRCK_ORDR_NUM = 8523 ) AS TEMP

Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1278
Location: Belgium

PostPosted: Tue Sep 22, 2009 5:12 pm    Post subject:
Reply with quote

I'm pretty sure that the output of the query is NOT 5 rows.
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