Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- declare @time table (Timestamp datetime)
- declare @result2 table (DeviceId varchar(32), DeltaT float, [Timestamp] datetime, Avg30DaysDeltaT float);
- declare @result1 table (DeviceId varchar(32), DeltaT float, [Timestamp] datetime, Avg30DaysDeltaT float);
- declare @result3 table (DeviceId varchar(32), DeltaT float, [Timestamp] datetime, Avg30DaysDeltaT float, [Latitude] float, [Longitude]float);
- insert into @time select distinct Timestamp from [dbo].[Calculation] where [TimeStamp] >= '2019-03-01' AND [TimeStamp] <= '2019-04-17'
- insert into @result1 (DeviceId, DeltaT, [Timestamp], Avg30DaysDeltaT)
- select c.DeviceId
- , c.DeltaT
- , c.TimeStamp
- , c.Avg30DaysDeltaT
- From [dbo].[Calculation] as c
- where [TimeStamp] >= '2019-03-01' AND [TimeStamp] <= '2019-04-17'
- order by Timestamp desc
- insert into @result2 (DeviceId, DeltaT, [Timestamp], Avg30DaysDeltaT)
- SELECT
- cply.DeviceId
- , cply.DeltaT
- , t.[Timestamp]
- , cply.Avg30DaysDeltaT
- FROM @time as t
- CROSS APPLY (
- SELECT TOP 20
- hc.DeviceId
- , hc.DeltaT as DeltaT
- , hc.TimeStamp
- , hc.Avg30DaysDeltaT as Avg30DaysDeltaT
- FROM @result1 AS hc
- order by hc.DeltaT desc)as cply
- where t.TimeStamp >= '2019-03-01' AND t.[TimeStamp] <= '2019-04-17'
- --select * from @result2
- --order by Timestamp desc
- insert into @result3 (DeviceId , DeltaT, [Timestamp], Avg30DaysDeltaT, [Latitude], [Longitude])
- select r2.DeviceId
- , r2.DeltaT
- , r2.TimeStamp
- , r2.Avg30DaysDeltaT
- , s.[Latitude ] as [Latitude]
- ,s.[Longitude ] as [Longitude]
- from @result2 as r2
- inner join [dbo].[Structure] as s
- on s.DeviceId = r2.DeviceId
- where r2.TimeStamp >= '2019-03-01' AND r2.[TimeStamp] <= '2019-04-17'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement