Assistance Needed with Advanced Data Binning in InfluxQL Query

20 views Asked by At

I am currently working on a project where I need to perform some advanced data processing using InfluxQL, and I've encountered a challenge that I'm hoping you can assist me with.

I am trying to execute a query on my InfluxDB instance that involves not only filtering and grouping data but also binning a specific field (kw) into predefined ranges. The query structure I have in mind is as follows:

SELECT "kw", "status"
FROM "<bucket>"
WHERE time >= '2023-11-01T00:00:00+05:30' AND time <= '2023-11-12T00:00:00+05:30'
AND "siteId" = '<sites>'
AND "componentId" = '<component_id>'
AND "kw" <= 300
GROUP BY "componentId"

My requirement is to categorize the kw field values into bins (e.g., 0-50, 50-100, etc.). I understand that InfluxQL has certain limitations and does not directly support conditional statements like CASE for binning as in standard SQL.

Could you please advise on the best approach to achieve this within the InfluxDB environment? Are there any features or functions within InfluxQL that I might have overlooked, or would this require a different approach, possibly involving a combination of InfluxQL and post-query processing in a tool like Python?

Any guidance or suggestions you can offer would be greatly appreciated. I am open to exploring alternative methods or best practices that you might recommend for handling such scenarios.

I tried using this:

`SELECT 

CASE
WHEN "kw" BETWEEN 0 AND 50 THEN '0-50'
WHEN "kw" BETWEEN 50 AND 100 THEN '50-100'
WHEN "kw" BETWEEN 100 AND 150 THEN '100-150'

END AS kw_bin,"status"
FROM "<bucket>"
WHERE time >= '2023-11-01T00:00:00+05:30' AND time <= '2023-11-12T00:00:00+05:30'
AND "siteId" = '<sites>'
AND ("componentId" = '<component_id>')
AND "kw" \<= 300
GROUP BY "componentId"`

But this gives no results.

0

There are 0 answers