> select spread(humidity) from weather
name: weather
time spread
---- ------
⑤SUM()函数
返回一个字段中的所有值的和。字段的类型必须是长整型或float64。
语法:SELECT SUM(<field_key>) FROM <measurement_name> [WHERE <stuff>] [GROUP BY <stuff>
> select sum(humidity) from weather
name: weather
time sum
---- ---
0 -23
⑥INTEGRAL()函数
语法:SELECT INTEGRAL( [ * | <field_key> | /<regular_expression>/ ] [ , <unit> ] ) [INTO_clause] FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause]
> select INTEGRAL(temperature) from weather
name: weather
time integral
---- --------
0 497728.82358215
⑦distinc()函数
> select distinct(temperature) from weather
name: weather
time distinct
---- --------
0 10
0 11
7.limit限制条数
#显示一条信息
> select * from weather limit 1
name: weather
time altitude area humidity temperature
---- -------- ---- -------- -----------
1607604432455278300 1001 南 -5 10
#limit 10 offset 15,就是从第15行开始之后的10条数据
> select * from weather limit 2 offset 2
name: weather
time altitude area humidity temperature
---- -------- ---- -------- -----------
1607656662027484500 1001 南 -5 11
1607656706278952000 999 南 -5 11
influxDB中没有in的操作,但是有or。对于习惯了mysql的in来说,用or就需要在代码中循环了。
> select * from weather where altitude=1001 or temperature=11
name: weather
time altitude area humidity temperature
---- -------- ---- -------- -----------
1607656662027484500 1001 南 -5 11
1607656706278952000 999 南 -5 11
1607656751612223600 1002 西 -2 11
1607656799728402900 1003 东 -2 11
9.模糊查询
> select * from test
name: test
time app count host monitor_name num
---- --- ----- ---- ------------ ---
1585897703920290000 1 127.0.0.1 test
1585897983909417000 ios 2 127.0.0.1 test1 3
1585898383503216000 ios 2 127.0.0.1 test1 3
1585901694441000000 ios 2 127.0.0.1 app1 3
1585901704179677000 ios 2 127.0.0.1 ios1 3
## =~/给定字段/ 包含指定字段的
> select * from test where monitor_name =~/app/
name: test
time app count host monitor_name num
---- --- ----- ---- ------------ ---
1585901694441000000 ios 2 127.0.0.1 app1 3
##=~/^给定字段/ 以指定字段开始的
> select * from test where monitor_name =~/^app/
name: test
time app count host monitor_name num
---- --- ----- ---- ------------ ---
1585901694441000000 ios 2 127.0.0.1 app1 3
##=~/给定字段$/ 以指定字段结尾的
> select * from test where monitor_name =~/p1$/
name: test
time app count host monitor_name num
---- --- ----- ---- ------------ ---
1585901694441000000 ios 2 127.0.0.1 app1 3
10.展示tag
> show tag keys from weather
name: weather
tagKey
------
altitude
#查询单个tag的value值
#查询所以tag为altitude的value的值
> show tag values from weather with key="altitude"
name: weather
key value
--- -----
altitude 1000
altitude 1001
altitude 1002
altitude 1003
altitude 999