Query data with SQL
Learn to query data stored in InfluxDB using SQL.
- Explore your schema with SQL
- Perform a basic SQL query
- Aggregate or apply selector functions to data
- Cast values to different types
Explore your schema with SQL
When working with InfluxDB’s implementation of SQL, a bucket is equivalent to a databases, a measurements is structured as a table, and time, fields, and tags are structured as columns.
List columns in a measurement
SHOW COLUMNS IN measurement
Perform a basic SQL query
A basic SQL query that queries data from InfluxDB most commonly includes
SELECT temp, room FROM home WHERE time >= now() - INTERVAL '1 day'
Aggregate or apply selector functions to data
Use aggregate and selector functions to perform aggregate operations on your time series data.
Aggregate fields by groups
SELECT mean(field1) AS mean, selector_first(field2)['value'] as first, tag1 FROM home GROUP BY tag
Aggregate by time-based intervals
SELECT DATE_BIN(INTERVAL '1 hour', time, '2022-01-01T00:00:00Z'::TIMESTAMP) AS time, mean(field1), sum(field2), tag1 FROM home GROUP BY time, tag1
Cast values to different types
CAST function or double-colon
:: casting shorthand syntax to cast a value to a specific type.
-- CAST clause SELECT CAST(1234.5 AS BIGINT) -- Double-colon casting shorthand SELECT 1234.5::BIGINT
Was this page helpful?
Thank you for your feedback!
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for InfluxDB and this documentation. To find support, use the following resources:
InfluxDB Cloud and InfluxDB Enterprise customers can contact InfluxData Support.