4.InfluxDB-InfluxQL basic grammar tutorial - Basic select statement

This translation from the official website, the official website address :( https://docs.influxdata.com/influxdb/v1.7/query_language/data_exploration/ )
The basic syntax is as follows:

SELECT <field_key>[,<field_key>,<tag_key>] FROM <measurement_name>[,<measurement_name>]

Visible, select the statement by the FROM clause SELECT clause and composed.


A, SELECT clause

In the SELECT clause, there are the following forms, which are used to access a variety of data designated:

grammar meaning
SELECT * All queries and tags measurement in the fields. Examples sql:select * from h2o_feet;
SELECT "<field_key>" Queries a specified field. Examples sql:select water_level from h2o_feet;
SELECT "<field_key>","<field_key>" Query multiple field. Examples sql:select "level description", "water_level" from h2o_feet;
SELECT "<field_key>","<tag_key>"  Query specified field and tag. Example sql: select water_level,location from h2o_feet; Note : in the SELECT clause, if it contains a tag, the case must specify at least one field. For example, the following sql is wrong, because it only select a tag, but no field:select location from h2o_feet;
SELECT "<field_key>"::field,"<tag_key>"::tag Like the above, but also query the specified field and tag. :: [field | tag] syntax is used to specify the type of identifier, because sometimes tag and field may have the same name, so use :: [field | tag] to distinguish syntax.

In the SELECT clause, further comprising a mathematical operation , aggregate functions , basic type conversion , regular expressions .


Two, FROM clause

FROM clause measurement you want to query, to support the following syntax:

grammar meaning
FROM <measurement_name> Query data from the specified measurement. This approach will DB from the current default retention policy to query the measurement data.
FROM <measurement_name>,<measurement_name> Query data from a plurality of measurement in
FROM <database_name>.<retention_policy_name>.<measurement_name> From the specified DB, measurement specified in the query data retention policy
FROM <database_name>..<measurement_name> From the specified DB, the default retention policy of measurement data query

FROM clause also supports regular expressions .

About quotes

If measurement, tag, field and other identifiers in addition to [Az, 0-9, _], there are other characters, or identifier is keyword keyword must be enclosed in double quotes when referenced. For example, in the table h2o_feet in, "level description" is a field with a space, in this way, when queried, it must be in double quotation marks. Below, in the query level description double quotes if not, an error is reported.

Official recommendation, although some identifier is not necessary to use double quotes, but it is recommended to use double quotes identifiers for all!


Examples sql

  1. Query the measurement tag and all from a single measurement in the field

  2. Queries the specified tag and field from a single measurement of

  3. Tag and specified query from a single measurement of the field, and specify the type of their identity

    . This mode uses less.

  4. All queries from field measurement in

    The SELECT clause supports combining the * syntax with the :: syntax.

  5. Perform basic mathematical operations in the query

    InfluxDB follow the standard four arithmetic rules. See More Actions Mathematical Operators .

  6. Meanwhile queries all of their data from a plurality of measurement in

  7. Query from a full path of the measurement data

    visible, so-called full path, in fact, refers in the FROM clause, you specify the DB measurement is located, as well as to query the data retention policy is located.

  8. 查询指定数据库中的measurement的数据

    The query selects data in the NOAA_water_database, the DEFAULT retention policy, and the h2o_feet measurement. The .. indicates the DEFAULT retention policy for the specified database.


Frequently Asked Questions about the SELECT statement

In the SELECT clause, must be at least a field key! If only one or more of the tag key in the SELECT clause, then the query returns empty. This embodiment is the result of the underlying storage data InfluxDB caused.
Example :


The above query results are returned empty, because it's the SELECT clause, only query the location of this tag key.
If you want to query any data with location related to the tag key is in the SELECT clause must contain at least a field key, as follows:


Guess you like

Origin www.cnblogs.com/suhaha/p/11692115.html