Home All Groups Group Topic Archive Search About

Calculate integral of time series

Author
17 Feb 2006 3:48 AM
Ami Einav
Hello,
I want to compute an integral of values in a table that has 2 columns:
Column A: Time-stamp (T)
Column B: value (KWH)
I need to compute the sum of (KWH*(T(n)-T(n-1)))

Could you suggest a way to do it in T-SQL?

thanks
Ami

Author
17 Feb 2006 8:27 AM
Joe Care
Ami Einav wrote:
>I need to compute the sum of (KWH*(T(n)-T(n-1)))
Ad an autoincrementing id to your Table named idTbl
Assuming Tbl as Your Tablename
SELECT Tbl.T, Tbl2.T, Tbl.KWH , Tbl.KWH*(Tbl.T-Tbl2.T) as KWHt
FROM Tbl
    INNER JOIN Tbl as Tbl2 on Tbl2.idTbl+1 = Tbl.idTbl

Maybe you a datetime - conversion to get the calculation work.

in the step Goup/Sum it together as you like

greetings,
J.C.
Author
17 Feb 2006 11:00 AM
Ami Einav
Thanks Joe - that's exactly what I was looking for.
Ami

Show quote
"Joe Care" <u18810@uwe> wrote in message news:5c0163d5b2f02@uwe...
> Ami Einav wrote:
>>I need to compute the sum of (KWH*(T(n)-T(n-1)))
> Ad an autoincrementing id to your Table named idTbl
> Assuming Tbl as Your Tablename
> SELECT Tbl.T, Tbl2.T, Tbl.KWH , Tbl.KWH*(Tbl.T-Tbl2.T) as KWHt
> FROM Tbl
>    INNER JOIN Tbl as Tbl2 on Tbl2.idTbl+1 = Tbl.idTbl
>
> Maybe you a datetime - conversion to get the calculation work.
>
> in the step Goup/Sum it together as you like
>
> greetings,
> J.C.

AddThis Social Bookmark Button