Forum

Posted by Prasad, Feb. 15, 2022, 12:49 p.m.

Question 69

How my below MySQL solution is wrong for Question #69
select count(customer_id)
from
(select customer_id, day(return_ts) day,
(lead(day(return_ts))over(partition by customer_id order by day(return_ts))-
day(return_ts))diff
from rental
where month(return_ts) =5
and day(return_ts)>=24
and day(return_ts) <=31) as inn
where diff is not null;
and diff<=1

Answers

Your basic formula looks ok, but there's a couple of issues to consider:
1) You're using the return date - does this classify all rentals for the timeframe?
2) What would happen if someone had multiple rentals on a given day, but not on the next, would that still classify as a happy customer by the listed requirements?
SQLPad user avatar

Mike (228)

Feb. 16, 2022, 1:25 p.m.