sql server - Help with finding the difference (delta) from a value returned from the last two records -
I'm using MS SQL 2005 and I have created a CTE query to return the values of the last two records . I then use it to return the two data delta. I have a type of query, but I'm having trouble finding anything except delta data
Here's my query:
(with selection NetObjectID, RawStatus, RowID, the RN (select CustomPollerAssignmentID NetObjectID, RawStatus, RowID, as RN where CustomPollerStatistics_Detail as the ROW_NUMBER () (CustomPollerAssignmentID = 'a87f531d-4842-4bb3- 9d68-7fd118004356 ') (DATETIME order by desc)) x where RN & lt; = 2), then select the case when the maximum (case when RN 1 RawStatus end) & gt; Maximum (case RN when 2 then RawStatus end) then max (case RN when 1 then RawStatus end) - Maximum (case RN when 2 then RawStatus end) and max (case RN when 2 and RawStatus end) - Max (RN case when 1 then RawStatus end) the data from the delta as the end (select case when the maximum (RN case when 1 then RawStatus end) & gt; max ( When the case RN 2 then RawStatus end) then max (case RN when 1 then RawStatus end) - Maximum (case RN when 2 then RawStatus end) and max (case R.ank when 2 then RawStatus end) - Max (RN case when 1 then RawStatus end) end of data) & gt; = 1 What Delta & amp; Every time I try NetObjectID, I get errors. The data.NetObjectID is invalid in the selection list because it is not in the section by any work or group.
If I try to add an Ad Group. The end of the query gives me more error in complaining about the word 'group'. I
I'm relatively new to SQL and I'm picking up things as I go.
See if such a thing will work or not.
(select NetObjectID, RawStatus, RowID, more than RN (CustomPollerStatistics_Detail the RN as CustomPollerAssignmentID NetObjectID, RawStatus, RowID, ROW_NUMBER () (by DATETIME desc as orders) select where x (-4bb3-9d68-7fd118004356 ') with the data as CustomPollerAssignmentID =' a87f531d-4842) where RN & lt; = 2) Choose NetObjectID, Max (RawStatus) cleaning MIN ( RawStatus from Data Group by NetObjectID as Delta
Comments
Post a Comment