Shane
Shane

Reputation: 1075

How do I count the number of occurances of a value in Influx? (GROUP BY?)

I have a bunch of data in InfluxDB about "articles", and each article has a domain value associated with it.

I was hoping to display the number of articles, by domain. I might be wrong, but I feel like what I want in SQL is this:

select domain, count(*) from articles group by domain;

However, this gives me this error:

ERR: mixing aggregate and non-aggregate queries is not supported

What am I doing wrong?

Upvotes: 1

Views: 2658

Answers (2)

I suspect that your domain is a field and not a tag. You can only group by a tag (and time intervals). If your domain was a tag there would be no problem with the query. Although selecting the tag could be redundant since it is already included in the results as the group identifier.

I think Jan Garaj's comment is somewhat inaccurate.

I don't know why you don't get an error that you can't group by domain if it is in fact a field. But perhaps the query parser is just first complaining about you having a field that is in fact not being aggregated in any way when it should be.

EDIT: but to address your question, the way you approach it is the right way.

Upvotes: 1

Jan Garaj
Jan Garaj

Reputation: 28626

You need to use correct InfluxDB syntax for GROUP BY (tag is not included in the SELECT clause):

select count(*) from articles group by domain;

Upvotes: 0

Related Questions