InfluxDB中未搭配聚合函数的GROUP BY查询为何能成功执行?
Great question! This might feel counterintuitive if you're coming from standard SQL, but it's a deliberate design choice in InfluxDB's query language (InfluxQL). Let's break down exactly why your query works:
InfluxQL has relaxed GROUP BY rules for time series data
Unlike standard SQL, which enforces that every non-aggregated column in yourSELECTclause must be included in theGROUP BYclause, InfluxQL handles this differently. When you group by a tag (likeNAMEhere, which is almost certainly a tag given typical InfluxDB schemas), InfluxDB automatically applies an implicitLAST()aggregate function to all fields in yourSELECT *statement. In short, it returns the most recent value of each field for every unique group defined byNAME.The
FILL(null)clause doesn't impact query validity
YourFILL(null)parameter is just instructing InfluxDB how to handle gaps in the result set (though since you're grouping by a tag rather than time, its effect is minimal here). It doesn't change the core logic of howGROUP BYworks in InfluxQL—it only modifies how missing values are displayed.Tag-based grouping is optimized for time series use cases
InfluxDB is built specifically for time series data, where grouping by tags (like device names, locations, or categories) is a common operation. The implicit aggregation behavior is a convenience: instead of writingSELECT NAME, LAST(field1), LAST(field2) ..., you can useSELECT *to quickly get the latest state of each field per tag group.
To put it in concrete terms: if your sampleTable has a tag NAME and fields like temperature and humidity, your query would return the last recorded temperature and humidity values for each unique NAME in the table.
内容的提问来源于stack exchange,提问作者cSharma

