Error on running influx query

I am trying to extract the mean of used_percent and display the value of host in the table using api, But it shows me the error:

error parsing query: mixing aggregate and non-aggregate queries is not supported

I am running this query:
select mean(used_percent),host from mem where time > now() - 5m group by host

Please guide.

1 Like

Change that to select mean(used_percent) from mem where time > now() - 5m group by host. You’re already grouping by host so you don’t need to select it as well.

Thanks Mark, this query does not show the host name as output. I need to show hostname and the corresponding mean value in table.

The grouped by tags are present in the JSON response under results.series.tags rather than results.series.values.

If that doesn’t work for you, there’s probably a way to make this work with subqueries. Off the top of my head, I’m not sure what that would look like.

Thank you Mark.

I am using this link: http://influxdb-python.readthedocs.io/en/latest/resultset.html#
to get the results.

E.g if I am running this:
rs = cli.query(“select mean(used_percent) from mem where time > now() - 5m group by host”)
mem_points = list(rs.get_points(measurement=‘men’))
print mem_points

it shows only values, how can I use tags here

I’m also hitting this problem, and although I gather that the grouped-by tag names might be available in the JSON results, I don’t think that helps me because I’m trying to use this form of query as a subquery. I want to use the tag name in the outer query, so I want to pass that name through to the outer query. Certainly the query has meaning, so it’s unfortunate that it isn’t supported. I’d like to lobby for its support.

(FWIW, I have a related problem when using selectors on two fields, and again trying to pass a tag name through to an outer query. That is, this bug: https://github.com/influxdata/influxdb/issues/7802)