How to show most frequent value


How to show the value that appears most often in, for example, 10 minutes time?
I’m using Influxdb database.

What is your value? Tag or field?

It is field…

SELECT MODE("value") 
FROM measurement
WHERE time>NOW()-10m


Thank you. One more question. Do you know if “group by” time is absolute or relative?
Let’s say that the time is 18:35
Group by is set to 10m
Will it choose median from values that were sent to database from 18:25 to 18:35 or 18:30 to 18:40?

Sorry, you should read doc first:

So, according to this when there is Group by: time(10m) it is absolute time range. I’ve tried setting Group by: time(now()-10m) but it is not working in Grafana. Do you know how to set relative time there?

Just in case it’s something simple like this, I wanted to pass along so you can easily test to confirm whether or not this may be your issue. . .

SELECT MODE("value") 
FROM measurement
WHERE time>NOW()-10m AND $timeFilter

Or maybe this syntax instead

SELECT MODE("value") 
FROM measurement
WHERE $__timeFilter(time)>NOW()-10m

No, this is relative time range, not absolute time range.


According to InfluxDB compared to SQL databases which I believe is an Influx official document right off their site, it states:

You can also use relative time with now() which refers to the server’s current timestamp… ~measure where the timestamp is newer than the server’s current time minus one hour

To me this seems to indicate what you are trying to accomplish is possible regarding “relative time” from now and the last 10 minutes from now. Maybe its a matter of the format of the output of the time stamp more than the time you are worried about but getting the records from now minus x seems to be getting the relative time regardless.

Furthermore, here’s a couple of posts that may have helpful information including one that seems to have maybe a query as you describe so these may at least be worth a read to you regarding the matter:

Please note I’m not familiar that much with Influx and I’m more an SQL guy and use Grafana more with MySQL than anything in case that makes any difference but from the query examples I see, the language looks similar. I mentioned using $__timeFilter() in your queries though to help it scale and such based on the time filter selected within the dashboard or whatever by the way.