Posted by Tobias, April 29, 2022, 7:56 a.m.
Question 43
Why doesn't this approach work in question 43 but in 42 it does. Both questions are from my understanding quite similar.
My Solution for Q43:
with cr as
(
SELECT c.customer_id
, case when count(r.rental_id) is Null then 0 else count(r.rental_id) end as count
FROM customer as c
left join rental as r on r.customer_id=c.customer_id
where date(r.rental_ts)<= '2020-05-31' and date(r.rental_ts)>= '2020-05-01'
group by c.customer_id
)
select case when count > 0 then 'rented' else 'never-rented' end as hass_rented
, count(*) as count
From cr
group by hass_rented