Calculate difference between readings

P

PD

My data as follows;

Asset_Name Asset_Type Property Generated_At Value
Widget1 Press CoreTemp 1/1/2008 08:05:00AM 123.1
Widget1 Press CoreTemp 1/1/2008 08:06:35AM 154.0
Widget3 Boiler FWTemp 1/1/2008 08:05:30AM
75.3

I need to add a column which calculates the difference between the values
for like Assets and Properties. I have a query that gives me the elapsed
time between readings, but I can not seem to use the same technique to
retrieve the value difference. See below for elapsed time query...

SELECT T2.Monitor_Value, T2.Asset_Name, T2.Asset_Type, T2.Property,
T2.Generated_At, (SELECT Min(Generated_At)
FROM Questra T3
WHERE T3.Asset_Name = T2.Asset_Name
AND T3.Asset_Type = T2.Asset_Type
AND T3.Property = T2.Property
AND T3.Generated_At>T2.Generated_At) AS NextReading
FROM Questra AS T2
ORDER BY T2.Asset_Name, T2.Asset_Type, T2.Property, T2.Generated_At;

My goal is to calculate rate of change for each reading.

Thanks,
 
P

PD

Thanks Marshall,

That worked just fine.
--
PRD


Marshall Barton said:
Try using:

T2.Monitor_Value - (SELECT TOP 1 Value
FROM Questra T4
WHERE T4.Asset_Name = T2.Asset_Name
AND T4.Asset_Type = T2.Asset_Type
AND T4.Property = T2.Property
AND T4.Generated_At < T2.Generated_At
ORDER BY T4.Generated_At DESC) AS DeltaValue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top