Forum

Posted by Mandeep, Feb. 25, 2024, 3:03 a.m.

Q44 in-demand-vs-not-in-demand-movies

I am not sure why my answer is wrong

/*
    1. For data safety, only SELECT statements are allowed
    2. Results have been capped at 200 rows
*/

 

with tmp as 
  (
  select extract(month from r.rental_ts) as month,
            extract(year from r.rental_ts) as year,
            f.film_id,
            count(r.rental_id) as rentals
  from film f 
  left join inventory i on i.film_id = f.film_id
  left join rental r on r.inventory_id = i.inventory_id
  and extract(month from r.rental_ts) = 5 
  and extract(year from r.rental_ts) = 2020
  group by 1,2,3
  )
  
  select case when rentals > 1 then 'in demand' 
               else 'not in demand' end as demand_category,
               count(film_id) as count
               from tmp
               group by demand_category

I would love to have an explanation how this query is different from the actual answer.
Thanks

This question is closed

Answers

Hey Mandeep,

Looks like you've included films that are not actually in inventory, if you break down your query and compare it with our solution step by step, you will see the differnece.

 

Hope it helps,

Leon

SQLPad user avatar

Leon (949)

March 24, 2024, 11:45 a.m.