I have a table with objects that defines some endpoint to test latency on (structure), a table to hold the results (latencies), and a table of each "target" (place where the endpoint is tested)
I want to get the average latency for each time interval for a specific structure from all locations that it is being hit from
The timestamps are in 10 minutes intervals (differing by ~1 second) for each target under that structure
I'm having issues with grouping by the timestamp where formatting the timestamp (to remove the second difference) and casting it back to a datetime loses it locale (stored in UTC but appears to come out in local time)
Is there some better way to go about this or some way to format a date s.t. the locale is preserved?
SELECT
structure.Id as TargetId,
Avg(latencies.Latency) as Latency,
latencies.Timestamp
FROM StructureTable structure
INNER JOIN TargetsTable targets on targets.StructureId = structure.Id
Outer apply
(
Select
CAST(format(Timestamp, 'yyyy-MM-dd hh:mm:00') as DATETIME) as Timestamp,
Latency,
TargetId
from LatenicesTable
where TargetId = targets.Id and Timestamp < endDate and Timestamp > startDate
) as latencies
where structure.Id = structureId and latencies.Latency > 0
group by latencies.Timestamp
order by latencies.Timestamp asc
EDIT: results example w/ format + Cast
Id Latency Timestamp
22 546 2021-05-09 01:00:00.000
22 540 2021-05-09 01:10:00.000
22 535 2021-05-09 01:20:00.000
22 543 2021-05-09 01:30:00.000
22 551 2021-05-09 01:40:00.000
22 546 2021-05-09 01:50:00.000
and w/o
Id Latency Timestamp
22 548 2021-05-09 05:00:02.313
22 471 2021-05-09 05:00:02.453
22 619 2021-05-09 05:00:02.547
22 607 2021-05-09 05:00:02.593
22 477 2021-05-09 05:00:02.937
22 561 2021-05-09 05:10:01.627
22 641 2021-05-09 05:10:01.657
22 470 2021-05-09 05:10:01.673
22 481 2021-05-09 05:10:01.893
22 617 2021-05-09 05:10:02.000