How to calculate OHLCV data from tick data in influxdb?

I try to query with flux script, but got trouble with that, please take a look at the question. The script prints nothing,
How to calculate OHLCV data from tick data in influxdb? - Stack Overflow

Hello @Heo,
Welcome! For a candlestick function I’d try the following: