Problem on SELECT with difference function, grouped by time and tag - not work

Hello there,

I’m relatively new user of influx (a couple of months). Any problems I had in past with influx I solved by documentation or by googling. but now it seems I really need some help from more experienced users.

I facing to problem with selecting data from one retention policy, to another using function difference, but i still get empty result.

Situation is:

I have default retention policy with raw data called “data_raw” where i have stored measurements from 64bit counter.(measurements are for network switches and ports) So in the retention policy is one measurement called “result_port” and tag called “port_id” to hold unique id of the port and some fields, for example port_data_in

It looks like: some_database_name.data_raw.result_port.port_id.port_data_in

What i need to do is get all data from “data_raw” retention policy under measurement “result_port” and put them in to another retention policy(by continuous query) where I will have absolute data from counter. This can be achieved (as I know) by aggregation function difference. So i tried to run:

SELECT mean(*) INTO “database”.“data_absolute”.:MEASUREMENT FROM (SELECT difference(port_data_in) AS “port_data_in” FROM “database”.“data_raw”.“result_port” GROUP BY * ) GROUP BY *, time(1m);

for me it seems like correct solution, but the result is nothing - empty.

When i try without grouping it by time (only by tags) the result seems correct but the time is 0:

SELECT mean(*) INTO “database”.“data_absolute”.:MEASUREMENT FROM (SELECT difference(port_data_in) AS “port_data_in” FROM “database”.“data_raw”.“result_port” GROUP BY * ) GROUP BY *;

Version of influx db is 1.7.2
Now I’m really stuck on this and don’t know what to do.

I will appreciate any suggestions. Thank you very much.

Michal.

I have found a solution. It seems that difference needs LAST and WHERE time to work:

SELECT difference(last(port_data_in)) AS port_data_in FROM “database”.“data_raw”.result_port WHERE time > now() - 1m GROUP BY time(1m), *

Michal.