Customer Retention and Churn Analysis | Part 2 | SQL Intermediate Question 6

Поділитися
Вставка
  • Опубліковано 14 жов 2024

КОМЕНТАРІ • 2

  • @nidhisingh4973
    @nidhisingh4973 6 місяців тому

    Thank you. Do you think this will work for not consecutive month order date and different year order date. Suppose cust_id 1 has ordered in Jan, Feb and May. So ideally this id should come for Feb churn analysis but this will not come with this solution approach.
    Please correct me if I am wrong.

  • @Naveen-uz4hw
    @Naveen-uz4hw 4 місяці тому

    select distinct cust_id
    from
    (select *
    ,min(order_date) over(partition by cust_id order by order_date) as min_date
    ,max(order_date) over(partition by cust_id order by order_date desc) as max_date
    from transactions)a
    where (month(max_date)-month(min_date))=1