Dynamic group by with mysql plugin

Hello. Is exist way to make dynamic group by via mysql plugin depend on selected time interval?

Condition for group:

1 year - group by year
<=1 year - group by month
<=1 month - group by day
<=1 day - group by hour

I use grafana: 5.0
Db - Mariadb 10.2.13

it is possible to do this but not with the grafana supplied timeGroup macro. You would have use your own function/expression to calculate the group by interval in mariadb.