Posted by Egor, Aug. 29, 2022, 1:24 a.m.
69 : Number of happy customers
Make sure you included 2020-05-31.
Posted by Egor, Aug. 29, 2022, 1:24 a.m.
Make sure you included 2020-05-31.
I think your main problem is a bit of data ballooning by selecting all the columns in your CTE, when really you just need the customer_id and to calculate the difference between rentals.
Also, I'm not sure it's required per se, but I would partition by the customer_id in your window function vs ordering - it makes it drastically more clear what you're trying to do vs filtering it later with the customer_id = p_c.
Hi, Mike
Yes, thanks, I was experimenting with the possibility of not using partitioning, however, I've edited the code in the way you suggested, and it gives the same results, coz I used distinct only for customer id, hence it doesn't matter which columns are being returned from CTE(from a results perspective, ofc we should bring only data we need).
Sorry, threading isn't working in the forum at the moment so had to add a different answer.
In your CTE where clause, change the rental_ts to rental_ts::date and remove the ::timestamp from the strings, then change your primary where clause to just = instead of <=.