I have a very basic group by query in Athena where I would like to use an alias. One can make the example work by putting the same reference in the group by, but that's not really handy when there's complex column modifications going on and logic needs to be copied in two places. Also I did that in the past and now I have a statement that doesn't work by copying over.
Problem:
SELECT
substr(accountDescriptor, 5) as account,
sum(revenue) as grossRevenue
FROM sales
GROUP BY account
This will throw an error:
alias Column 'account' cannot be resolved
The following works, so it's about the alias handling.
SELECT
substr(accountDescriptor, 5) as account,
sum(revenue) as grossRevenue
FROM sales
GROUP BY substr(accountDescriptor, 5)