CASE Multiple values on Athena Presto

Viewed 302

I'm looking for some advice.

I have multiple values that I wish to code to the same output, but Athena doesn't seem to recognise the SQL.

CASE customer_name
WHEN 'Aa' or 'Ar' or 'Aar' or 'Aaro' THEN 'Aaron' END as customer_name

I want to avoid doing the below:

CASE customer_name
WHEN 'Aa' THEN 'Aaron'
WHEN 'Ar' THEN 'Aaron'
WHEN 'Ar' THEN 'Aaron'
WHEN 'Ar' THEN 'Aaron'
END as customer_name
1 Answers

You can move the field into the 'WHEN' clause:

WITH dataset ( customer_name) AS
(
  VALUES
      ('Aa'),
  ('Ar'),
  ('Ar'),
  ('Ar'),
  ('B')
)

 SELECT
    CASE
        WHEN customer_name IN ('Aa', 'Ar', 'Aar', 'Aaro') THEN 'Aaron'
    END AS customer_name
FROM dataset

Output:

customer_name
Aaron
Aaron
Aaron
Aaron
 
Related