I'm moving SQL from Redshift to AWS Athena, but I'm having trouble because the SQL is giving me errors.
SELECT abc_name AS bca_name,
CASE
WHEN name = 'aaa' THEN 'AAC'
WHEN name = 'bbb' THEN 'BBA'
WHEN name = 'ccc' THEN 'CCB'
END AS abc
FROM master_table
WHERE abc IS NOT NULL;
This SQL gave me an error: it says that there is no abc column because abc in the where clause is read earlier than in the select clause.
How can I get this to work?