[FIX] Queries group by migration

Implements [ticket 3018](https://www.openproject.org/work_packages/3018)