Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InfluxDB select top n results from a group by tag

Tags:

influxdb

I have a data set of devices and the number of (un)instalmments of my app that are done daily.

A sample data would be:

 time | device_name | daily_installs | daily_uninstall
  t1  |   device1   |       0        |       1
  t1  |   device2   |       2        |       0
  t2  |   device2   |       2        |       0
  t2  |   device3   |       12       |       0

I can group them by device_name and get the total of install that I have by month (or any other range) for example.

But the amount of device is huge, hence I would like to filter only the top 10.

How can I achieve that using InfluxDB?

like image 304
DiogoLG Avatar asked Dec 16 '16 15:12

DiogoLG


People also ask

How do I get unique values in InfluxDB?

DISTINCT() returns the unique values of a single field. The field values are meant to be the actual data you're interested in. Tag values are metadata: data about the data. Most functions in database systems operate on the data or the metadata, but rarely on both.

How do I query data from InfluxDB?

To perform an InfluxQL query, send a GET request to the /query endpoint, set the URL parameter db as the target database, and set the URL parameter q as your query. You can also use a POST request by sending the same parameters either as URL parameters or as part of the body with application/x-www-form-urlencoded .

What is InfluxQL?

InfluxQL is an SQL-like query language for interacting with data in InfluxDB. The following sections detail InfluxQL's SELECT statement and useful query syntax for exploring your data.

What is difference between tag and field in InfluxDB?

Fields are a necessary entity of building the database which are “non-indexed” hence they get scanned for all values when queried. Tags on the other hand are not a necessary but indexed entities that make the queries more performant.


1 Answers

Version 1.3.4

SELECT top(monthly_uninstalls,device_name,10) 
FROM (SELECT count(daily_uninstall) as monthly_uninstall 
      FROM mymeasurement 
      WHERE time > now() - 4w 
      GROUP BY device_name)

Please note that the syntax is "top("field_name", "tag", "topN") from ...."

like image 196
Ehud Lev Avatar answered Sep 26 '22 08:09

Ehud Lev