1、The Group by clause and fill()
一般情况下,一个group by 间隔时间用null输出代表没有值的数据,可用fill()来改变没有值 的输出方式。fill()选项包括
- 任何数字
- null:设置null为间隔内没有数据的输出
- previous:复制前一个间隔的值作为没有数据的输出
- none:跳过没有值
以下的例子可以看出fill()的用法
GROUP BY without fill()
例子1
SELECT MEAN(water_level) FROM h2o_feet WHERE time >= ‘2015-08-18‘ AND time < ‘2015-09-24‘ GROUP BY time(10d)结果
name: h2o_feet
--------------
time mean
2015-08-13T00:00:00Z 4.306212083333323
2015-08-23T00:00:00Z 4.318944629367029
2015-09-02T00:00:00Z 4.363877681204781
2015-09-12T00:00:00Z 4.69811470811633
?2015-09-22T00:00:00Z
GROUP BY with fill()例子2Use fill()
with -100
:
SELECT MEAN(water_level) FROM h2o_feet WHERE time >= ‘2015-08-18‘ AND time < ‘2015-09-24‘ GROUP BY time(10d) fill(-100)
结果
name: h2o_feet -------------- time mean 2015-08-13T00:00:00Z 4.306212083333323 2015-08-23T00:00:00Z 4.318944629367029 2015-09-02T00:00:00Z 4.363877681204781 2015-09-12T00:00:00Z 4.698114708116322 ?2015-09-22T00:00:00Z -100
例子3Usefill()
withnone
:
SELECT MEAN(water_level) FROM h2o_feet WHERE time >= ‘2015-08-18‘ AND time < ‘2015-09-24‘ GROUP BY time(10d) fill(none)
结果
name: h2o_feet
--------------
time mean
2015-08-13T00:00:00Z 4.306212083333323
2015-08-23T00:00:00Z 4.318944629367029
2015-09-02T00:00:00Z 4.363877681204781
2015-09-12T00:00:00Z 4.69811470811633
?
注意:如果你用GROUP(ing) BY一些东西(如,有tags和一上时间间隔),fill()必须放在group by 的最后。
时间: 2024-10-12 17:57:43