MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

db2 query needed

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Wed Jul 25, 2007 5:47 am    Post subject: db2 query needed Reply with quote

Hai All,

I have written a query which is retreiving data in the format below:
Code:

SELECT TABLEA.A,TABLEB.B,TABLEB.C   
FROM                                 
TABLEA,TABLEB                       
WHERE TABLEA.X = TABLEB.Y           
GROUP BY TABLEB.B,                   
         TABLEA.A,                   
         TABLEB.C                   
ORDER BY TABLEB.B;                   

A           B                        C                                 
---------+---------+---------+---------+---------+---------+---------+--
1           TOM                      11.50                             
1           CHRIS                    20.50                             
1           LUCY                     15.00                             
1           LUCY                     16.00                             

I want the output as below and the data is presumed to as i have specified
Code:

A           B                        C                                 
---------+---------+---------+---------+---------+---------+---------+--
1           TOM                      11.50                             
1           CHRIS                    20.50                             
1           LUCY                     31.00                                

Can anyone help me with the desired query ?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed Jul 25, 2007 6:24 am    Post subject: Reply with quote

yadav2005,

Try this untested code

Code:

SELECT TABLEA.A
      ,TABLEB.B
      ,SUM(TABLEB.C)   
  FROM TABLEA
      ,TABLEB                       
 WHERE TABLEA.X = TABLEB.Y           
 GROUP BY TABLEB.B                   
         ,TABLEA.A                   
 ORDER BY TABLEB.B
;                   


Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Wed Jul 25, 2007 6:40 am    Post subject: Reply with quote

Kolusu,

Thanks for your reply and i am able to get the desired results.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group