• i am trying to learn something here ok not copying or doing any cheating

    this is by far i have tired

    ;with cte (month, totalchargedamount)
    As
    (
    Select  c.monthindex ,sum(a.charged_amount)as totalcharged
    From lineitems a  join invoice b on a. invoiceID = b. invoiceID
    right Join months c on b.month = c.monthIndex
    group by monthindex)
    ,cta(month,total)
    as
    (

    select b.month,(a.totalchargedamount- b.totalchargedamount)/100 as total
    from cte a  join cte b on b.month-1 = a.month)

    select a.month,totalchargedamount,total from cte a left  join cta b
    on a.month = b.month
    but  i want to learn good easy way than this