Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Divide result of one query by result of another query / CASE WHEN type functionality #5383

Open
gvohra opened this issue Jan 17, 2016 · 8 comments
Labels
1.x area/influxql Issues related to InfluxQL query language flux/triaged

Comments

@gvohra
Copy link

gvohra commented Jan 17, 2016

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

@strongpauly
Copy link

+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...

@e-dard
Copy link
Contributor

e-dard commented Nov 30, 2016

See #3552

@e-dard e-dard added the area/influxql Issues related to InfluxQL query language label Nov 30, 2016
@phemmer
Copy link
Contributor

phemmer commented May 12, 2017

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

@shivambhandari99
Copy link

+1

@hackertron
Copy link

is it implemented yet !!

@stale
Copy link

stale bot commented Oct 1, 2019

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.

@stale stale bot added the wontfix label Oct 1, 2019
@excitoon
Copy link

excitoon commented Oct 1, 2019

That would be a great feature to have.

@stale stale bot removed the wontfix label Oct 1, 2019
@wasrek404
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x area/influxql Issues related to InfluxQL query language flux/triaged
Projects
None yet
Development

No branches or pull requests

10 participants