Tracking Service Upgrades (T-SQL query)

  • I need your ideas for this task.

    I have a history table storing clients services per month (Serv1, Serv2, Serv3)

    I need to count per month customers who upgraded from Serv1 to either 2 or 3, but need each both. For example.

    Month        Serv1-To_Serv2       Serv1_To_Serv3

    January          500                      100

    .

    .

    December       10                       55

    Thanks in advance

  • This is what I have. Am I right?.

    SELECT

    a.data_date

    ,count(case when serv1 = 'N' and serv2 = 'Y' then cust_id else null end) as from1to2

    ,count(case when serv1 = 'N' and serv3 = 'Y' then cust_id else null end) as from1to3

    from tableA A

    left join tableA B on A.cust_id = B.cust_id

    and a.data_date = dateadd(mm,1,b.data_date)

    group by a.data_date

    order by a.data_date

     

     

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply