influxdb – influxdb query for if/else case

influxdb didn’t support if/else in select statement.

mysql could support if/else/case statement, for example.

1
2
3
4
5
6
7
   SELECT
      CASE <field>
         WHEN 1 THEN 100
      ELSE
         0
   FROM TABLE
   WHERE [condition]

However, influxdb didn’t support if/else in select statement.
we have to use a function map for if/else

for example,

input set is (1, 2, 3, 4, 5, 6, 7)
output set is (100, 0, 0, 0, 0, 0, 0)

we design a function f(x) = 100*FLOOR(1/x)

so f(1) = 100, f(2) = 0, … , f(7) = 0;

it could match whole input set and output set

1
SELECT 100*FLOOR(1/FIELD) FROM 'measurement' WHERE <condition>