influxdata / influxdata/docs-v2

Add info about InfluxQL GROUP BY time() with time bounds behavior in subqueries

Open
#5,269 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

InfluxDB v2 InfluxQL product:v2 product:v2-cloud
Dominant language
JavaScript
Stars
82
Forks
326
Avg merge
1d 1h
Merged PRs (30d)
82

Description

If you use `GROUP BY time()` in a subquery _and_ include time bounds in the `WHERE` clause, the `WHERE` clause has to be to be in the inner query before the `GROUP BY` clause, not the outer query. Otherwise the query returns no results.

For example, the following query doesn't return any results:

```sql
SELECT
mean("price") AS "mean_price"
FROM
(
SELECT
MEAN("price") AS "price"
FROM
"bitcoin".."coindesk"
GROUP BY
"code",
time(1d)
)
WHERE
time >= '2023-01-01T00:00:00Z'
AND time < '2023-02-01T00:00:00Z'
```

However, the following query does return results:

```sql
SELECT
mean("price") AS "mean_price"
FROM
(
SELECT
MEAN("price") AS "price"
FROM
"bitcoin".."coindesk"
WHERE
time > '2023-01-01T00:00:00Z'
AND time < '2023-02-01T00:00:00Z'
GROUP BY
"code",
time(1d)
)
```

##### Relevant URLs

- https://docs.influxdata.com/influxdb/v2/query-data/influxql/explore-data/subqueries/
- https://docs.influxdata.com/influxdb/cloud/query-data/influxql/explore-data/subqueries/

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the InfluxQL subqueries documentation at the linked InfluxDB URLs and compare the existing guidance with the two example queries in the issue. Document that time bounds must be placed in the inner query before GROUP BY time() for results to be returned, using the examples to show the differing behavior.

Written by the indexing model from the issue text.

Assessment

Domain
databases, documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.