Group by time() throws error

I am trying to fetch all data points from my measurement, “Concentration” between a specified time range, but I want it grouped by a time interval of 30 seconds. I have tried following query,

SELECT * FROM Concentration WHERE time >= ‘2022-03-16T11:39:00Z’ AND time <= ‘2022-03-16T12:30:00Z’ GROUP BY time (30s)

However, I receive following error:
ERR: error parsing query: found (, expected ; at line 1, char 115

This query works just fine if I remove ‘group by’ clause.

I have recently decided to move from Mongo to Influx, and InfluxDB concepts are a little all over the place for me currently. Any help will be appreciated.
Thanks!

you got an extra space in there GROUP BY time(30s)

Thank you for quick response, Giovanni!

I removed the space as well but I get another error now,
ERR: GROUP BY requires at least one aggregate function

I think its because group by can be used only when you perform some function on the values when you fetch them, but I can be wrong.
I simply want all the fields in my dataset between a time range, grouped by 30 seconds.

I solved the problem. I simply used first () function as an aggregator function.
My query looks as follows,

SELECT FIRST(*) FROM Concentration WHERE time >= ‘2022-03-16T11:39:00Z’ AND time <= ‘2022-03-16T12:30:00Z’ GROUP BY time(10s) fill(none)

If you want all the points you don’t want to use aggregations but a simple filter.
first() will get only the first value (of each field) for the defined time window.

Also if you are using tags, they will be ignored in your current query, if you want to include them you must use GROUP BY *,time(__), where * stands for group by all tags

as a sample, in the following dataset (where Server is a tag)

time | Server | Cpu | Memory
2022-03-16 16:00:00 | Server1 | 10 | 4  --This one
2022-03-16 16:00:01 | Server2 | 14| 6
2022-03-16 16:00:08| Server1 | 26| 2
2022-03-16 16:00:08| Server2 | 12 | 4
2022-03-16 16:00:12| Server1 | 13 | 9  --This one
2022-03-16 16:00:12| Server2 | 21 | 4
2022-03-16 16:00:17| Server1 | 18 | 5
2022-03-16 16:00:18| Server2 | 16 | 4

a query like yours SELECT FIRST(*) FROM __ WHERE __ GROUP BY time(10s) fill(none) will get you this result (based on the rows marked above…)
the tag server is not even considered as the tags are not specified in the group by

time | Server | Cpu | Memory
2022-03-16 16:00:00 | 10 | 4
2022-03-16 16:00:10| 13 | 9