1.插入语句
# INSERT语句用于向数据库中插入数据点(数据行)。
# 这些数据点包含时间戳、测量(measurement)、标签(tags)和字段(fields)等信息。
# 以下是INSERT语句的基本语法
INSERT [OPTIONS] <measurement_name>, [tag_set] [field_set] [timestamp]
measurement_name: 数据被写入的测量名称。
tag_set: 标签集,由逗号分隔的键值对组成。标签是用于索引和过滤数据的关键字。
field_set: 字段集,由逗号分隔的键值对组成。字段包含实际的数据值。
timestamp: 时间戳,表示数据点的时间。可以是UNIX时间戳或RFC3339格式的时间字符串
示例:
INSERT temperature,location=room1 value=25.5 1641301322
temperature是测量名称。
location=room1是一个标签,表示数据点的位置。
value=25.5是一个字段,表示温度值。
1641301322是数据点的时间戳(UNIX时间戳)。
这里要注意的是时间是零时区,与国内相差了8小时,需要进行转换
2.普通查询
seLect * from test;
select * form test where person name='xu';
# 返回是将每张表不同记录返回
select * from test,student;
# 前缀匹配 ,相当于 mysqL 的 Like "admin%’
select * from test where person_name=~/^admin/
# 后缀匹配 ,相当于 mysqL 的 Like "%admin"
select * from test where person_name=~/admin$/
# 前后匹配,相当于 mysqL 的 Like "%admin%"
select * from test where person_name=~/admin/
3.聚合函数
#查询某个field字段的中的非空值数量
select count(age) from test;
select distinct(age) from test;
# 这个平均值必须是数字类型
select mean(age) from test;
select median(age) from test;
# 返回字段的最小值和最大值之间的差值。数据的类型必须是长整型或float
select spread(age) from test;
select sum(age) from test;
# 返回一个字段中最小的N个值。字段类型必须是长整型或float
select bottom(age,3) from test;
select first(age) from test;
select last(age) from test;
select max(age) from test
4.分组聚合
#查询所有数据,并对其划分为每200毫秒一组
select count(age) from test group by time(200ms)
#查询所有效据,并对其划分为200秒一组
select count(age) from test group by time(200s)
#查询所有致据,并对其划分为每12分钟一组
select count(age) from test group by time(12m)
#查询所有数据,并对其划分为每12小时一组
select count(age) from test group by time(12h)
#查询所有数据,并对其划分为每12天一组
seLect count(age) from test group by time(12d)
#查询所有政据,并对其划分为每12周一组
select count(age) from test group by time(12w)
5.分页查询
limit 用法有2种:
1.limit 10: 查询前10条数据
2.limit pageSize offset N; pageSize表示每页条数,N表示第几条记录开始
# 查询前10条数据
select * from test limit 10;
# 分页,pageSize 为每页条数,pageNo代表第几页
pageNo = 1 pageSize = 10
select * from test limlt pageSize offset (pageNo-1)*pageSize
6.排序
# 升序
select * from test order by time asc;
# 降序
select * from test order by time desc;
7.in操作
select * from test where person_name=~/^admin$|^username$/