InfluxQL group by with InfluxDb 2.x

This query works :

SELECT criteriaMetric, criteriaOperator, criteriaErrorThreshold, metricStatus 
FROM "qualityGateMetricValue" GROUP BY criteriaMetric, criteriaOperator, criteriaErrorThreshold, metricStatus

But what I want is to count the number of occurences of each distinct combination like I would do in SQL :

SELECT criteriaMetric, criteriaOperator, criteriaErrorThreshold, metricStatus, count(*)
FROM "qualityGateMetricValue" GROUP BY criteriaMetric, criteriaOperator, criteriaErrorThreshold, metricStatus

and this gives :

"error":"mixing aggregate and non-aggregate queries is not supported"

Is there a way to do this last SQL query in InfluxQL ?

P.S. : my columns are all tags except “metricStatus” which is a field. Is it important ? if it is, I can change the model, it’s not a problem.

Hello @Tristan107,
Welcome! Have you tried using distinct()?
https://docs.influxdata.com/influxdb/v1.8/query_language/functions/#distinct

Hi Anais, from the page you are proposing, “distinct()” is for one field only, and I have 4 tag/fields.

I think the answer to my question should be very straight forward :
“Yes of course, you can do that with InfluxDb” or “No, for this use case, InfluxDb does not allow you to do what you can do with SQL”
because my example is not an obscure specific use case, it’s just the most simple example of “group by” you can do in SQL.

Hello @Tristan107,
I apologize I don’t use InfluxQL much anymore since I find Flux much easier to use, so I’m rusty.
I don’t know the full extent of the problem you’re trying to solve to know whether or not there isn’t some alternative solution that would satisfy your needs with InfluxQL. I was trying to point you in a direction of something that might be helpful.
But I think you got your answer from the error message already, so I didn’t want to be redundant.

Well, what I try to do is this SQL query using InfluxDb. If you have a solution with Flux, it is very welcome :slightly_smiling_face: