Historian数据库中sql查询数据的方法

1,查询实时值,从live表中查询,tag名为Item_0

select * from live WHERE TagName = 'Item_0'

返回结果

2,查询历史值,从history表中查询,tag名为Item_0

select * from history WHERE TagName = 'Item_0'
and DateTime < '2021-06-04 15:00:00'
and DateTime >= '2021-06-04 13:00:00'

返回结果如下

 

 

 

3,向history表中插入数据,tag名为test_insert1

INSERT INSQL.Runtime.dbo.AnalogHistory
(DateTime, TagName, Value, OPCQuality, wwVersion)
VALUES('2021-6-4 14:05:10', 'test_insert1', 17, 192, 'LATEST')

查询一下结果

select * from history WHERE TagName = 'test_insert1'
and DateTime < '2021-06-04 15:00:00'
and DateTime >= '2021-06-04 13:00:00

结果如下

 

4,查询宽表

 

SELECT
    * 
FROM
    OpenQuery ( INSQL, 'SELECT 
    DateTime, Item_0 
FROM 
    Runtime.dbo.WideHistory   --Runtime.dbo.是可选的
WHERE  
    Item_0 > 15000' )

 

查询结果

 

 

5,查询模拟量表

SELECT
    Tagname,
    OPCQuality,
    Minimum AS MIN,
    Maximum AS MAX,
    Average AS AVG
    FROM AnalogSummaryHistory
    WHERE TagName = 'Item_0' 
    AND StartDateTime >= dateadd( MINUTE,-60,Getdate()) 
    AND EndDateTime < getdate()
    AND wwCycleCount = 2

 

查询结果

 

AnalogSummaryHistory视图是一个“宽”视图(),允许您在单个查询中为单个标记返回多个统计信息。

如上图所示,最小值、最大值、平均值。

 

 

 

 

 

posted @ 2021-06-04 16:02  Iamseeking  阅读(908)  评论(0编辑  收藏  举报