'How to extract my hotwater consumption from influxdb

My 'heating' database holds a measurement 'heating-sensors' with the fields 'total_consumption' and 'hotwater_pump'. I'd like to extract the fuel consumption (wood pellets) while the 'hotwater_pump' is 1 grouped by weeks. The total_consumption value increases monotonously, the 'hotwater_pump' value is either 0 or 1.

Probably quite easy for someone more into databases than me, I tried:

select difference("total_consumption") * "hotwater_pump" from "heating-sensors"

but this only yields

ERR: mixing aggregate and non-aggregate queries is not supported

and

select difference("total_consumption") from "heating-sensors" where "hotwater_pump" = 1

works so far, but then I can't sum it and group it. I don't know how to tackle that ...

BTW: This is influxdb 1.6.4 on Ubuntu 20.04



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source