Influxdb: Divide result of one query by result of another query / CASE WHEN type functionality

Created on 17 Jan 2016  路  8Comments  路  Source: influxdata/influxdb

Hi there

I realise this is probably trivial to do, but I've searched the docs / GitHub issues and could not find a solution.

I would like to divide the result of one query by the result of another. I am using Grafana on top of InfluxDB, and would like to establish how many rows of data are within a certain target range.

Essentially, dividing the result from the top query by the result from the bottom query:

image

An alternative would be something like the following in T-SQL:

SELECT sum(CASE WHEN value < 25 THEN 1 ELSE 0 END) / count(value) from "ui.thread_switch" where $timeFilter

Does such CASE WHEN type functionality exist in InfluxDB?

I feel like this should be possible but I'm not sure how. Please could someone point me in the right direction :)? That'd be much appreciated!

Thanks,
Gaurav

1.x areinfluxql flutriaged

Most helpful comment

+1

All 8 comments

+1: I agree influx should support this this kind of functionality. Without it means storing data as booleans is a lot less useful than storing it as either 0 or 1 because you want to be able to do things like:

SELECT SUM(CASE WHEN booleanValue THEN 1 ELSE 0 END) FROM measurement...

For the CASE WHEN, I would also like to propose that in addition to CASE WHEN <expression> ... we also support CASE <value> WHEN <comparison> ....

The former CASE WHEN <expression1> THEN foo WHEN <expression2> THEN bar ELSE baz END is referred to as a "case expression" in relational databases.
Example: CASE WHEN color == 'red' THEN 3 WHEN color == 'blue' THEN 2 WHEN color == 'green' THEN 1 ELSE 0 END

The latter CASE <value> WHEN <comparison1>, <comparison2> THEN foo WHEN <comparison3> THEN bar ELSE baz END CASE is referred to as a "case statement" in relational databases.
Example: CASE color WHEN 'red' THEN 3 WHEN 'blue' THEN 2 WHEN 'green' THEN 1 ELSE 0 END CASE

+1

is it implemented yet !!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

That would be a great feature to have.

+1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Raniz85 picture Raniz85  路  3Comments

756445638 picture 756445638  路  3Comments

jayannah picture jayannah  路  3Comments

airyland picture airyland  路  3Comments

robinjha picture robinjha  路  3Comments