Thanks but it’s not working. Can’t get all the "Chills’ together. This seems to always sort by genre:
SELECT name,
CASE
WHEN genre = 'romance' THEN 'Chill'
WHEN genre = 'comedy' THEN 'Chill'
ELSE 'Intense'
END AS 'Mood'
FROM movies
WHERE genre IS NOT NULL
ORDER BY 'Mood';
If it is using the genre to order rows, how can I bring up ‘comedy’ then ‘romance’ then the rest in that order?
I wonder why there has to be a comma after ‘SELECT name’ from the code below.
And also curious about why ‘FROM movie’ has to be at the end.
SELECT name,
CASE
WHEN imdb_rating > 8 THEN ‘Fantastic’
WHEN imdb_rating > 6 THEN ‘Poorly Received’
ELSE ‘Avoid at All Costs’
END AS ‘Review’
FROM movies;
In this example, is it not possible to use OR along with the CASE statement. Something like below.
SELECT name,
CASE
WHEN genre = ‘romance’ OR genre = ‘comedy’ THEN ‘Chill’
ELSE ‘Intense’
END AS ‘Mood’
FROM movies;
Hi, I’m very curious, why this code:
SELECT name,
CASE
WHEN imdb_rating > 8 THEN ‘Fantastic’
WHEN imdb_rating > 6 THEN ‘Poorly Received’
ELSE ‘Avoid at All Costs’
END
FROM movies;
print a column with “CASE WHEN imdb_rating > 8 THEN 'Fantastic’ WHEN imdb_rating > 6 THEN ‘Poorly Received’ ELSE 'Avoid at All Costs’ END AS ‘Review’ “ as column name?
It’s either greater than eight or it’s not. Failing that it’s either greater than six, or it’s not. Everything falls through naturally without any between tests.