Grouping aggregations with expresssions are currently not allowed and you have to use sub-selects to workaround it.
Example that does not work
select name,avg(cast(system as int)) from system_tables group by name order by name
and workaround
select name,avg(sys) from (select name,cast(system as int) as sys from system_tables)
Grouping aggregations with expresssions are currently not allowed and you have to use sub-selects to workaround it.
Example that does not work
and workaround