Subquery with group by time in outer query

SELECT mean(DCTBH) from (SELECT derivative(“CTBH”, 1d) as DCTBH FROM “sensors” WHERE $timeFilter) GROUP BY time(1h)

returns “aggregate function required inside the call to derivative”

Is this the expected behavior?

Hello @nathanp,

Yes. Your query needs to look like this:

SELECT DERIVATIVE(AGGREGATION_FUNCTION(<field_key>),[<unit>]) FROM <measurement_name> WHERE <stuff> GROUP BY time(<aggregation_interval>)

Please take a look at the documentation and this issue for more help.



That doesn’t do the same thing as the intent of my query. With that syntax the aggregate function is applied first, then the derivative. I want to apply the derivative first, then the aggregate function. Is that possible?