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

How to get the SUM value of the below query


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Tue Sep 22, 2009 1:45 am
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
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

Moderator Emeritus


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

PostPosted: Tue Sep 22, 2009 2:38 am
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: 193
Location: chennai

PostPosted: Tue Sep 22, 2009 11:13 am
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
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: 1281
Location: Belgium

PostPosted: Tue Sep 22, 2009 5:12 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top