Forum

Posted by kavita, May 29, 2022, 8:03 a.m.

43. Customers who rented vs. those who did not - Question related to solution

Hi,

Your solution has different query , doing the below query is right 

 

select 
hass_rented,count(*)
from (
SELECT distinct c.customer_id,
case when  r.rental_id is not null then 'rented'
when r.rental_id is  null then 'never-rented' end as hass_rented 

FROM customer as c
left join  rental as r
on c.customer_id  =r.customer_id  
and extract(month from r.rental_ts)=5
and extract(year from r.rental_ts)=2020)final 
group by hass_rented

Answers

Hey Kavita,

There are multiple ways to solve the same problem with different queries, it's okay (and encouraged) to come up with your own solution.

Your solution looks correct, but I would suggest you reformat your code a bit and follow a. consistent coding style (e.g., using UPPERCASE for all keywords). 😁

SQLPad user avatar

Leon (949)

May 29, 2022, 8:48 a.m.