In version 0.8 there was an example where I could do mathematical operations with an inner join function like this:
select hosta.value - hostb.value
from cpu_load as hosta
inner join cpu_load as hostb
where hosta.host = 'hosta.influxdb.orb' and hostb.host =
'hostb.influxdb.org';
Is that use case not supported anymore at all or how should I structure my data model so that I can achieve the same results?
@Rainer_Hahnekamp You can now store multiple fields in each measurement. Performing math across them works as you have specified. You might find these docs pages useful:
Thanks for your answer, but the documentation didn’t help me. My use case is that I am measuring energy data from different meters (slighty different timestamps). I am using a tag to identify the meter and need to calculate KPIs.
So what I had now in mind was to calculate the differen between these two by a inner join
select (meter1.value - meter2.value) * 1.780
from meters as meter1 inner join meters as meter2
where meter1.meter = 'ENERGY_METER1' and meter2.meter = 'ENERGY_METER2'
sorry for the very late answer. If your question is still valid, my Kapacitor script for inner joining two measurements separated by the tags “field1” and “field2” looks like the following:
var field1 = batch
|query('select mean(value) from "data"."autogen".linedata where prettyname = \'Field Nr 1\'')
.period(1d).every(1d).groupBy(time(1h)).fill(0)
var field2 = batch
|query('select mean(value) from "data"."autogen".linedata where prettyname = \'Field Nr 2\'')
.period(1d).every(1d).groupBy(time(1h)).fill(0)
field1
|join(field2).as('field1', 'field2')
|eval(lambda: max(("field1.mean" - "field2.mean") * 3.144, 0.0)).as('value')
|influxDBOut().database('data').measurement('linedata').tag('prettyname', 'Field Nr 3')