Querying the AnalogSummaryHistory view
- Last UpdatedMar 20, 2025
- 1 minute read
The AnalogSummaryHistory view is a "wide" view that allows you to return multiple statistics for a single tag within a single query.
The following query returns the minimum, maximum, and average values for the SysTimeSec tag for the last hour.
declare @End datetime
set @End = left(convert(varchar(30),getdate(),120),14)+'00:00'
SELECT Tagname, OPCQuality, Minimum as MIN, Maximum as MAX, Average as AVG
FROM AnalogSummaryHistory
WHERE TagName = 'SysTimeSec'
AND StartDateTime >= dateadd(minute,-60,@End)
AND EndDateTime < @End
AND wwCycleCount = 2
The results are:
|
Tagname |
OPCQuality |
MIN |
MAX |
AVG |
|
SysTimeSec |
192 |
0 |
59 |
29.5 |
Note: When querying the AnalogSummaryHistory view, a data point occuring at the same timestamp as the EndDateTime is not considered part of the query interval. Instead, it is treated as the first data point in the next interval beginning at EndDateTime, and so is not included in the maximum or average value calculations.