New York Restaurants: How are case statements read?

In the lesson:

We create this code:

SELECT name,
	WHEN review > 4.5 THEN 'Extraordinary'
  WHEN review > 4 THEN 'Excellent'
  WHEN review > 3 THEN 'Good'
  WHEN review > 2 THEN 'Fair'
 	ELSE 'Poor'
 END AS 'Review'
FROM nomnom;

Does the order of the WHEN statements matter? How does the compiler read the information? For example if the code was ordered where 4.5 was after 4 would that change the results? Thanks.

1 Like

That would certainly change the result! Case statements are like if…else if…else block. When the first condition is met(true), the code after THEN will be run or printed, otherwise the code after the else block will be run! So when your review is 5.0 and your ‘‘review > 4’’ is above ‘‘review > 4.5’’ then ‘Excellent’ will be returned though 5.0 is also greater than 4.5.