View previous topic :: View next topic
|
Author |
Message |
abdulrafi
Active User
Joined: 14 Sep 2009 Posts: 184 Location: Coimbatore
|
|
|
|
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 |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
|