Search code examples
influxdb

Select every hour query


I have a simple weather station DB with example content:

time                humi1 humi2 light pressure station-id temp1 temp2
----                ----- ----- ----- -------- ---------- ----- -----
1530635257289147315 66    66    1834  1006     bee1       18.6  18.6
1530635317385229860 66    66    1832  1006     bee1       18.6  18.6
1530635377466534866 66    66    1829  1006     bee1       18.6  18.6

Station writes data every minute. I want to get SELECT not with all series, but just series written every hour (or every 60th series, simply said). How can I achieve it?

I tried to experiment with ...WHERE time % 60 = 0, but it didn`t work. It seems, that time column doesnt permit any math operations (/, %, etc).


Solution

  • Group by along with a one of the functions can do what you want:

    SELECT FIRST("humi1"), FIRST("humi2"), ... GROUP BY time(1h)

    I would imagine for most climate data you'd want the MEAN or MEDIAN rather than a single data point every hour

    basic example, and more complex example