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: 193
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: 1281
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 Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm


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