重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
作用:返回一个字段在一个series中的变化率。
创新互联公司是一家专注于成都网站建设、成都网站制作与策划设计,蓟州网站建设哪家好?创新互联公司做网站,专注于网站建设10多年,网设计领域的专业建站公司;建站业务涵盖:蓟州等地区。蓟州做网站价格咨询:028-86922220InfluxDB会计算按照时间进行排序的字段值之间的差异,并将这些结果转化为单位变化率。其中,单位可以指定,默认为1s。
语法:
SELECT DERIVATIVE(, [ ]) FROM [WHERE ]
其中,unit取值可以为以下几种:
u --microsecondss --secondsm --minutesh --hoursd --daysw --weeks
DERIVATIVE()函数还可以在GROUP BY time()的条件下与聚合函数嵌套使用,格式如下:
SELECT DERIVATIVE(AGGREGATION_FUNCTION(),[ ]) FROM WHERE GROUP BY time( )
示例:
假设location = santa_monica 条件下数据有以下几条:
name: h3o_feet--------------time water_level2015-08-18T00:00:00Z 2.0642015-08-18T00:06:00Z 2.1162015-08-18T00:12:00Z 2.0282015-08-18T00:18:00Z 2.1262015-08-18T00:24:00Z 2.0412015-08-18T00:30:00Z 2.051
计算每一秒的变化率:
> SELECT DERIVATIVE(water_level) FROM h3o_feet WHERE location = 'santa_monica' LIMIT 5name: h3o_feet--------------time derivative2015-08-18T00:06:00Z 0.000144444444444444572015-08-18T00:12:00Z -0.000244444444444444652015-08-18T00:18:00Z 0.00027222222222222182015-08-18T00:24:00Z -0.0002361111111111112015-08-18T00:30:00Z 2.777777777777842e-05
第一行数据的计算公式为(2.116 - 2.064) / (360s / 1s)
计算每六分钟的变化率
> SELECT DERIVATIVE(water_level,6m) FROM h3o_feet WHERE location = 'santa_monica' LIMIT 5name: h3o_feet--------------time derivative2015-08-18T00:06:00Z 0.0520000000000000462015-08-18T00:12:00Z -0.088000000000000082015-08-18T00:18:00Z 0.097999999999999862015-08-18T00:24:00Z -0.084999999999999962015-08-18T00:30:00Z 0.010000000000000231
第一行数据的计算过程如下:(2.116 - 2.064) / (6m / 6m)
计算每12分钟的变化率:
> SELECT DERIVATIVE(water_level,12m) FROM h3o_feet WHERE location = 'santa_monica' LIMIT 5name: h3o_feet--------------time derivative2015-08-18T00:06:00Z 0.104000000000000092015-08-18T00:12:00Z -0.176000000000000162015-08-18T00:18:00Z 0.195999999999999732015-08-18T00:24:00Z -0.169999999999999932015-08-18T00:30:00Z 0.020000000000000462
第一行数据计算过程为:(2.116 - 2.064 / (6m / 12m)
计算每12分钟大值的变化率
> SELECT DERIVATIVE(MAX(water_level)) FROM h3o_feet WHERE location = 'santa_monica' AND time >= '2015-08-18T00:00:00Z' AND time < '2015-08-18T00:36:00Z' GROUP BY time(12m) name: h3o_feet--------------time derivative2015-08-18T00:12:00Z 0.0099999999999997872015-08-18T00:24:00Z -0.07499999999999973
这个函数功能非常多,也非常复杂,更多对于此功能的详细解释请看官网:https://docs.influxdata.com/influxdb/v0.13/query_language/functions/#derivative
作用:返回一个字段中连续的时间值之间的差异。字段类型必须是长整型或float64。
最基本的语法:
SELECT DIFFERENCE() FROM [WHERE ]
与GROUP BY time()以及其他嵌套函数一起使用的语法格式:
SELECT DIFFERENCE(( )) FROM WHERE GROUP BY time( )
其中,函数可以包含以下几个:
COUNT(), MEAN(), MEDIAN(),SUM(), FIRST(), LAST(), MIN(), MAX(), 和 PERCENTILE()。
使用示例
例子中使用的源数据如下所示:
> SELECT water_level FROM h3o_feet WHERE location='santa_monica' AND time >= '2015-08-18T00:00:00Z' and time <= '2015-08-18T00:36:00Z'name: h3o_feet--------------time water_level2015-08-18T00:00:00Z 2.0642015-08-18T00:06:00Z 2.1162015-08-18T00:12:00Z 2.0282015-08-18T00:18:00Z 2.1262015-08-18T00:24:00Z 2.0412015-08-18T00:30:00Z 2.0512015-08-18T00:36:00Z 2.067
计算water_level间的差异:
> SELECT DIFFERENCE(water_level) FROM h3o_feet WHERE location='santa_monica' AND time >= '2015-08-18T00:00:00Z' and time <= '2015-08-18T00:36:00Z'name: h3o_feet--------------time difference2015-08-18T00:06:00Z 0.0520000000000000462015-08-18T00:12:00Z -0.088000000000000082015-08-18T00:18:00Z 0.097999999999999862015-08-18T00:24:00Z -0.084999999999999962015-08-18T00:30:00Z 0.0100000000000002312015-08-18T00:36:00Z 0.016000000000000014
数据类型都为float类型。
作用:返回一个字段在连续的时间间隔间的差异,间隔单位可选,默认为1纳秒。
语法:
SELECT ELAPSED(, ) FROM [WHERE ]
示例:
计算h3o_feet字段在纳秒间隔下的差异。
> SELECT ELAPSED(water_level) FROM h3o_feet WHERE location = 'santa_monica' AND time >= '2015-08-18T00:00:00Z' and time <= '2015-08-18T00:24:00Z'name: h3o_feet--------------time elapsed2015-08-18T00:06:00Z 3600000000002015-08-18T00:12:00Z 3600000000002015-08-18T00:18:00Z 3600000000002015-08-18T00:24:00Z 360000000000
在一分钟间隔下的差异率:
> SELECT ELAPSED(water_level,1m) FROM h3o_feet WHERE location = 'santa_monica' AND time >= '2015-08-18T00:00:00Z' and time <= '2015-08-18T00:24:00Z'name: h3o_feet--------------time elapsed2015-08-18T00:06:00Z 62015-08-18T00:12:00Z 62015-08-18T00:18:00Z 62015-08-18T00:24:00Z 6
注意:如果设置的时间间隔比字段数据间的时间间隔更大时,则函数会返回0,如下所示:
> SELECT ELAPSED(water_level,1h) FROM h3o_feet WHERE location = 'santa_monica' AND time >= '2015-08-18T00:00:00Z' and time <= '2015-08-18T00:24:00Z'name: h3o_feet--------------time elapsed2015-08-18T00:06:00Z 02015-08-18T00:12:00Z 02015-08-18T00:18:00Z 02015-08-18T00:24:00Z 0
作用:返回一个连续字段值的移动平均值,字段类型必须是长×××或者float64类型。
语法:
基本语法
SELECT MOVING_AVERAGE(, ) FROM [WHERE ]
与其他函数和GROUP BY time()语句一起使用时的语法
SELECT MOVING_AVERAGE(( ), ) FROM WHERE GROUP BY time( )
此函数可以和以下函数一起使用:
COUNT(), MEAN(),MEDIAN(), SUM(), FIRST(), LAST(), MIN(), MAX(), and PERCENTILE().
示例:
> SELECT water_level FROM h3o_feet WHERE location = 'santa_monica' AND time >= '2015-08-18T00:00:00Z' and time <= '2015-08-18T00:36:00Z'name: h3o_feet--------------time water_level2015-08-18T00:00:00Z 2.0642015-08-18T00:06:00Z 2.1162015-08-18T00:12:00Z 2.0282015-08-18T00:18:00Z 2.1262015-08-18T00:24:00Z 2.0412015-08-18T00:30:00Z 2.0512015-08-18T00:36:00Z 2.067
作用:返回在一个series中的一个字段中值的变化的非负速率。
语法:
SELECT NON_NEGATIVE_DERIVATIVE(, [ ]) FROM [WHERE ]
与聚合类函数放在一起使用时的语法如下所示:
SELECT NON_NEGATIVE_DERIVATIVE(AGGREGATION_FUNCTION(),[ ]) FROM WHERE GROUP BY time( )
此函数示例请参阅:DERIVATIVE()函数
作用:返回一个字段中的值的标准偏差。值的类型必须是长整型或float64类型。
语法:
SELECT STDDEV() FROM [WHERE ] [GROUP BY ]
示例:
> SELECT STDDEV(water_level) FROM h3o_feet name: h3o_feet--------------time stddev1970-01-01T00:00:00Z 2.279144584196145
示例2:
> SELECT STDDEV(water_level) FROM h3o_feet WHERE time >= '2015-08-18T00:00:00Z' and time < '2015-09-18T12:06:00Z' GROUP BY time(1w), location name: h3o_feet tags: location = coyote_creek time stddev---- ------2015-08-13T00:00:00Z 2.24372630801939852015-08-20T00:00:00Z 2.1212761501447192015-08-27T00:00:00Z 3.04161221707862152015-09-03T00:00:00Z 2.53480650254352072015-09-10T00:00:00Z 2.5840039548826732015-09-17T00:00:00Z 2.2587514836274414name: h3o_feet tags: location = santa_monica time stddev---- ------2015-08-13T00:00:00Z 1.111563445875532015-08-20T00:00:00Z 1.09098492790823662015-08-27T00:00:00Z 1.98701161800969622015-09-03T00:00:00Z 1.35167784509020672015-09-10T00:00:00Z 1.49605738115005882015-09-17T00:00:00Z 1.075701669442093
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。