--Calculate the average number of days between purchases for each customer
--(If a customer purchased books only once, do not return him).


select cid,
        cast    (
                (float
                        (max(DAYS(when)) - min(DAYS(when)))
                )
                /
                (float
                        (count(distinct(date(when)))-1)
                )
                as decimal(7,2)
                )
        as avg_gap
from yrb_purchase
group by cid
having count(distinct(date(when)))>1;

