Showing posts with label saved. Show all posts
Showing posts with label saved. Show all posts

Thursday, March 22, 2012

Calculate values between previous rows

First, thanks to all of those that post to this newsgroup. You've
saved me tons of development time. I am trying to calculate values
between previous rows in my table. The table looks something like
this:
ID Value
1 100
2 200
3 300
4 400
5 ?
I was wondering if there was a way to create an expression that would
calculate the difference between row 4 and row 1. I am expecting row 5
to be 300. I have looked at the previous function, but this does not
seem to be what I am looking for. Any ideas?
Thank you,
Scott Leandro
scottleandro_@.gmail.com (remove the _)save row1 value into a variable and then subtract from it
i.e.
set @.myValue = select value from table where ID = 1
then
select id , value -@.myvalue
from xxx
you might have to work around your design so that value for ID =1 won't
return 0
ken
scottleandro@.gmail.com wrote:
> First, thanks to all of those that post to this newsgroup. You've
> saved me tons of development time. I am trying to calculate values
> between previous rows in my table. The table looks something like
> this:
> ID Value
> 1 100
> 2 200
> 3 300
> 4 400
> 5 ?
> I was wondering if there was a way to create an expression that would
> calculate the difference between row 4 and row 1. I am expecting row 5
> to be 300. I have looked at the previous function, but this does not
> seem to be what I am looking for. Any ideas?
> Thank you,
> Scott Leandro
> scottleandro_@.gmail.com (remove the _)|||SQLKen,
Thanks for the reply. I wish I could do this in a SP, but
unfortunately I have to to do this calculation in a RS table cell
expression.
Thanks,
Scott
SQLKen wrote:
> save row1 value into a variable and then subtract from it
> i.e.
> set @.myValue = select value from table where ID = 1
> then
> select id , value -@.myvalue
> from xxx
> you might have to work around your design so that value for ID =1 won't
> return 0
> ken
>
> scottleandro@.gmail.com wrote:
> > First, thanks to all of those that post to this newsgroup. You've
> > saved me tons of development time. I am trying to calculate values
> > between previous rows in my table. The table looks something like
> > this:
> >
> > ID Value
> > 1 100
> > 2 200
> > 3 300
> > 4 400
> > 5 ?
> >
> > I was wondering if there was a way to create an expression that would
> > calculate the difference between row 4 and row 1. I am expecting row 5
> > to be 300. I have looked at the previous function, but this does not
> > seem to be what I am looking for. Any ideas?
> >
> > Thank you,
> > Scott Leandro
> > scottleandro_@.gmail.com (remove the _)sql