Posted by swetha, Dec. 11, 2023, 8:38 p.m.

quetion 35 order of execution

Hi 

I am trying to solve question 35,

I Solved it using this code

with cte1 as (
SELECT *,
case when length<60 then 'short'
when length >=60 and length <100 then 'medium'
else  'long'
end as Cat
FROM film
)
select cat, count(film_id)
from cte1
group by cat
 
 
but the solution provided is different where the case statement was directly in select statement
SELECT
  CASE WHEN length < 60 THEN 'short'
  	   WHEN length < 100 THEN 'medium'
  	   WHEN length >= 100 THEN 'long'
  	   ELSE NULL
  	   END AS film_category,
  COUNT(*)
FROM film
GROUP BY film_category;

Just have a question about order of execution of statements i know from statement is executed first then group by  then select   , but we dont have column film_category when execution is done right?

Answer

Answers


Comment
SQLPad user: Leon Wei

- Leon (934)

Dec. 16, 2023, 12:28 p.m.