Thank you for your help. Yes, current issue is a filling gaps. I have used grouping by tag:
SELECT zone, mean_value FROM (
SELECT mean(value) AS mean_value FROM temperature WHERE time > now() - 5h
GROUP BY time(1m), zone
)
In this case I have a result such as
{"time": "2021-07-08T07:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T07:00:00Z", "zone": "002temp", "mean_value": 24.7},
{"time": "2021-07-08T08:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T08:00:00Z", "zone": "002temp", "mean_value": 25.6},
{"time": "2021-07-08T09:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T09:00:00Z", "zone": "002temp", "mean_value": 26.0},
{"time": "2021-07-08T07:00:00Z", "zone": "001set", "mean_value": 195.5},
{"time": "2021-07-08T07:00:00Z", "zone": "002set", "mean_value": 195.6},
{"time": "2021-07-08T08:00:00Z", "zone": "001set", "mean_value": 200.0},
{"time": "2021-07-08T08:00:00Z", "zone": "002set", "mean_value": 200.0},
{"time": "2021-07-08T09:00:00Z", "zone": "001set", "mean_value": 200.0},
{"time": "2021-07-08T09:00:00Z", "zone": "002set", "mean_value": 200.0}
I’ve tried to use fill(0):
SELECT zone, mean_value FROM (
SELECT mean(value) AS mean_value FROM temperature WHERE time > now() - 5h
GROUP BY time(1m), zone fill(0)
)
I assumed that result should be like above plus additional 0 points for time 6:00:00 and 10:00:00, when device was switched off:
{"time": "2021-07-08T06:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T06:00:00Z", "zone": "002temp", "mean_value": 0.0},
{"time": "2021-07-08T07:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T07:00:00Z", "zone": "002temp", "mean_value": 24.7},
{"time": "2021-07-08T08:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T08:00:00Z", "zone": "002temp", "mean_value": 25.6},
{"time": "2021-07-08T09:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T09:00:00Z", "zone": "002temp", "mean_value": 26.0},
{"time": "2021-07-08T010:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T010:00:00Z", "zone": "002temp", "mean_value": 0.0},
{"time": "2021-07-08T06:00:00Z", "zone": "001set", "mean_value": 0.0},
{"time": "2021-07-08T06:00:00Z", "zone": "002set", "mean_value": 0.0},
{"time": "2021-07-08T07:00:00Z", "zone": "001set", "mean_value": 195.5},
{"time": "2021-07-08T07:00:00Z", "zone": "002set", "mean_value": 195.6},
{"time": "2021-07-08T08:00:00Z", "zone": "001set", "mean_value": 200.0},
{"time": "2021-07-08T08:00:00Z", "zone": "002set", "mean_value": 200.0},
{"time": "2021-07-08T09:00:00Z", "zone": "001set", "mean_value": 200.0},
{"time": "2021-07-08T09:00:00Z", "zone": "002set", "mean_value": 200.0}
{"time": "2021-07-08T010:00:00Z", "zone": "001set", "mean_value": 0.0},
{"time": "2021-07-08T010:00:00Z", "zone": "002set", "mean_value": 0.0},
But in this case it returns result that looks like “decart mutiplication” in SQL - for each result instance (row) from above results InfluxDB add additional points for each time interval (in the example below - from 6:00:00 to 10:00:00 with the step 1:00:00):
{"time": "2021-07-08T06:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T07:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T08:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T09:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T10:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T06:00:00Z", "zone": "002temp", "mean_value": 0.0},
{"time": "2021-07-08T07:00:00Z", "zone": "002temp", "mean_value": 24.7},
{"time": "2021-07-08T08:00:00Z", "zone": "002temp", "mean_value": 0.0},
{"time": "2021-07-08T09:00:00Z", "zone": "002temp", "mean_value": 0.0},
{"time": "2021-07-08T10:00:00Z", "zone": "002temp", "mean_value": 0.0},
{"time": "2021-07-08T06:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T07:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T08:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T09:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T10:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T06:00:00Z", "zone": "002temp", "mean_value": 0.0},
{"time": "2021-07-08T07:00:00Z", "zone": "002temp", "mean_value": 0.0},
{"time": "2021-07-08T08:00:00Z", "zone": "002temp", "mean_value": 25.6},
{"time": "2021-07-08T09:00:00Z", "zone": "002temp", "mean_value": 0.0},
{"time": "2021-07-08T10:00:00Z", "zone": "002temp", "mean_value": 0.0},
{"time": "2021-07-08T06:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T07:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T08:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T09:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T10:00:00Z", "zone": "001temp", "mean_value": 0.0},
{"time": "2021-07-08T06:00:00Z", "zone": "002temp", "mean_value": 0.0},
{"time": "2021-07-08T07:00:00Z", "zone": "002temp", "mean_value": 0.0},
{"time": "2021-07-08T08:00:00Z", "zone": "002temp", "mean_value": 0.0},
{"time": "2021-07-08T09:00:00Z", "zone": "002temp", "mean_value": 26.0},
{"time": "2021-07-08T10:00:00Z", "zone": "002temp", "mean_value": 0.0},
{"time": "2021-07-08T11:00:00Z", "zone": "002temp", "mean_value": 0.0},
etc
Queries that used as a subqueries (with and without fill) returned totally identical results!