Posted by Martin, July 3, 2023, 2:01 p.m.
q69
Hello.
I am curious regarding question 69, I have below code, which gives me an anser of 146, I cannot understand why it is not giving me the correct answer. Is it a missuse of lag-date or the lack of the min function?
Please have a look if possible:
"
with cte_ques_1 as (
select date(rental_ts), case when date_minus_lag<1 then 1 else 1 end as date_minus_lead_corr
from (
select *,
date(rental_ts),
lag(date(rental_ts),1) over(partition by customer_id) as lag1,
date(rental_ts)-lag(date(rental_ts),1) over(partition by customer_id) as date_minus_lag
from rental
where date(rental_ts)>='2020-05-24' and date(rental_ts)<='2020-05-31'
order by customer_id, rental_ts) x
where date_minus_lag=1 OR date_minus_lag=-1 )
select count(*)
from cte_ques_1
;
"