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
 

 

query in summing up the column values

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

Active User


Joined: 14 Sep 2009
Posts: 147
Location: Coimbatore

PostPosted: Fri Jul 15, 2011 3:50 pm    Post subject: query in summing up the column values
Reply with quote

Hi,

I need a query to sum the values of a particular column of db2 table.

My input is like this:

I_Persn Q_PENSN_HRS_CUR
103604 1972
103604 2001
103604 2040
103604 2048
103604 2068
103604 2072
103604 2236
103604 2262

My output needs to be like this:
103604 16699

I executed the query,

SELECT I_PERSN,SUM(Q_PENSN_HRS_CURR) AS PENSN_HRS_TOT
FROM U.UPPLRH WHERE D_PENSN_YR_CURR BETWEEN '1996' AND '2010'
GROUP BY I_PERSN,Q_PENSN_HRS_CURR;

Could anybody please help me on how to arrive on my output. :-(
Back to top
View user's profile Send private message

vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1504
Location: Chennai

PostPosted: Fri Jul 15, 2011 3:57 pm    Post subject:
Reply with quote

Hello,
You have not described about the variable D_PENSN_YR_CURR in the input file, but you have used it on your query?

For the above shown input and output,
Code:
select I_Persn,sum(Q_PENSN_HRS_CUR) as PENSN_HRS_TOT from U.UPPLRH
group by i_persn;
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Fri Jul 15, 2011 4:00 pm    Post subject:
Reply with quote

learn to use bbcode

Code:

I_Persn Q_PENSN_HRS_CUR
103604 1972
103604 2001
103604 2040
103604 2048
103604 2068
103604 2072
103604 2236
103604 2262

Code:

SELECT I_PERSN
      ,SUM(Q_PENSN_HRS_CURR) AS PENSN_HRS_TOT
FROM  U.UPPLRH
WHERE D_PENSN_YR_CURR BETWEEN '1996'
                          AND '2010'
GROUP BY I_PERSN
         ,Q_PENSN_HRS_CURR;

try this:
Code:

SELECT I_PERSN
      ,SUM(Q_PENSN_HRS_CURR) AS PENSN_HRS_TOT
FROM  U.UPPLRH
WHERE D_PENSN_YR_CURR BETWEEN '1996'
                          AND '2010'
GROUP BY I_PERSN
;


and in the future, also include sqlcodes that you recieved
and did not bother to look-up
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 Loading data to table gives wrong for... Raghu navaikulam DB2 18 Thu Jul 13, 2017 2:11 pm
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts Sorting of hex values Saurabh_mi DFSORT/ICETOOL 11 Thu May 25, 2017 3:49 pm
No new posts Replace values in the input data Vikas Maharnawar DFSORT/ICETOOL 10 Thu May 11, 2017 2:18 pm
No new posts Compare two files and subtract values ameetmund DFSORT/ICETOOL 7 Fri Mar 31, 2017 3:35 pm


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