To 🔥 celebrate the holiday season, Also check out our NEWLY launched Annual plan (Up to 50% off). Use coupon code THANKSGIVING15 and enjoy additional 15% off all paid plans. Coupon expires at 2020/11/30 .
73. Number of days to become a happy customer medium
- Any customers who made 10 movie rentals are happy customers
- Write a query to return the average number of days for a customer to make his/her 10th rental.
- If a customer has never become a ‘happy’ customer, you should skip this customer when computing the average.
- You can use
EXTRACT(DAYS FROM tenth_rental_ts - first_rental_ts)to get the number of days in between the 1st rental and 10th rental
ROUND(average_days)to return an integer
col_name | col_type --------------+-------------------------- rental_id | integer rental_ts | timestamp with time zone inventory_id | integer customer_id | smallint return_ts | timestamp with time zone staff_id | smallint last_update | timestamp with time zone
avg ------- 65