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
AmiAmi 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.|||Thanks Joe - that's exactly what I was looking for.
Ami
"Joe Care" <u18810@.uwe> wrote in message news:5c0163d5b2f02@.uwe...
> Ami Einav wrote:
> 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.sql
No comments:
Post a Comment