Shouldn't that be:

select, a.year, sum(a.amt + b.amt + c.amt)
from myfile a
inner join myfile b on = and b.year = (a.year + 1)
inner join myfile c on = and c.year = (a.year + 2)
group by, a.year

did you test it? I had a hard time wrapping my head around what would
happen the other way.

Mark Murphy
STAR BASE Consulting, Inc.

Charles Wilt <charles.wilt@xxxxxxxxx>
Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxx>
10/08/2009 04:01 PM
Re: SQL and a Running/Moving Total
Sent by:

select, a.year, sum(a.amt + b.amt + c.amt)
from myfile a
inner join myfile b on = and a.year = (b.year + 1)
inner join myfile c on = and a.year = (c.year + 2)
group by, a.year

Performance is not going to be great.
RPG records level access or an SQL cursor may be a better solution.


On Thu, Oct 8, 2009 at 3:40 PM, Mark Allen <scprideandms@xxxxxxxxx> wrote:
Table has 3 columns,Name,year,count and I need a total of the "count"
for each name over a 3 yr period, if there are NOT 3 years available
then no
output row.

Bill 1990 72
Bill 1991 73
Bill 1992 71
Bill 1993 55
Bill 1994 78
Bill 1995 73
Stan 1990 130
Stan 1991 122
Stan 1992 100
Stan 1993 115
Stan 1994 101
Stan 1995 112

What I want from the SQL output is

Bill 1990 216
Bill 1991 199
Bill 1992 204
Bill 1993 206
Stan 1990 352
Stan 1991 337
Stan 1992 316
Stan 1993 328
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2020 by and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].