CASE function syntax in fake_apps table lesson

Hi, I’m experimenting with the CASE function at the end of the Aggregate Function lesson using the fake_apps table. I input the following code to try to categorize the different app price levels, but the query is unsuccessful and the program won’t indicate why or how the syntax is incorrect:

SELECT id, name, category, ROUND(price, 2) AS price_rounded,
CASE
WHEN price_rounded >= 10 THEN ‘Expensive’
WHEN price_rounded >= 5 AND < 10 THEN ‘Moderate’
ELSE price_rounded < 5 THEN ‘Low’
END AS ‘Price_Level’
FROM fake_apps
LIMIT 5;

Can anyone help me debug this syntax?

Here’s the exercise link:
https://www.codecademy.com/paths/analyze-data-with-sql/tracks/analyze-data-sql-calculate-and-summarize-data/modules/dspath-sql-aggregates/lessons/aggregate-functions/exercises/review

Thanks, in advance.

Sorry, realized the LIMIT function was inadvertently left in the original code. Please see below updated version without LIMIT… still unsuccessful query:

SELECT id, name, category, ROUND(price, 2) AS price_rounded,
CASE
WHEN price_rounded >= 10 THEN ‘Expensive’
WHEN price_rounded >= 5 AND < 10 THEN ‘Moderate’
ELSE price_rounded < 5 THEN ‘Low’
END AS ‘Price_Level’
FROM fake_apps;

Should you have a condition with ELSE?

@codeneutrino, thanks for pointing that out. I think that line could be improved simply as the following:

ELSE ‘Low’

However, after attempting to run the code again, this edit still does not seem to generate a successful query.

Hi,

There is no ELSE in syntax for CASE statement. You have to replace ELSE with WHEN for the right syntax. In CASE statement you always have to use WHEN, when you are putting a condition.
You can use ELSE for a default value in case no condition for when is true.